pspad editor vb script to help with ruby on rails

I’ve been dabbling with ruby on rails (and ruby). Since I’m on windows, I don’t get to play with the mega-amazing-killer-editor-for-macs-only. So, I’m using pspad. It’s free, it’s lightweight and it’s good at what it does.
VBScript is kinda crappy. But hey, pspad supports it, so … here’s a small script I wrote to help with starting/stopping/browsing the webrick server on rails. copy, paste, save and enjoy. 🙂

Update: the code is posted at the pspad forum as well.

update: There’s some vbscript code to implement code completion for ruby here. Maybe I should take that code, build on it, and combine with my rails helper vbscript code.

update: The e-editor for windows is out (in bet form) now. Works with text mate bundles and uses cygwin to accomplish some of it’s tasks. Awesome!

' rails.vbs
' very simple rails helper script for use with pspad
' pspad is a wonderfule programmer's editor for windows
' free like all good things in life
' see http://www.pspad.com/
'
' could probably do a lot more than what i'm doing
' in this script.
'
' lapax at yahoo dot com
'
' only tested with pspad 4.5.0 (2175) and windows XP
' requires windows scripting host to be installed
' which probably comes installed with XP
'
' set your defaults e.g. DefaultRailsDir, Browser, Rubyexe
' unless the executables are in your path, you probably want
' to set the full path to the executables
'
' put this file in your pspadScriptVBScript directory
' either restart pspad or from menu run Scripts->Recompile Scripts
' you should get a new submenu called Rails
' Set your Rails Directory from that menu
'
' all blank lines have a remark character ' in front
' because of the way my wordpad parses the blog text
'
option explicit
const module_name = "Rails"
const module_ver = "0.1"
Dim DefaultRailsDir, Browser, Rubyexe
DefaultRailsDir = "c:projectsrubyrails"
Browser = "firefox"
Rubyexe = "ruby.exe"
'
' no need changing anything under here unless you're customizing the script
Dim RailsDir
RailsDir = ""
'
sub Test
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
msgbox WshShell.CurrentDirectory
Set WshShell = Nothing
end sub
'
'
function CheckRailsDir(dirstring)
if dirstring = "" then
CheckRailsDir = false
exit function
end if
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(dirstring) then
msgbox "Folder " + dirstring + " does not exist, aborting.", vbExclamation
CheckRailsDir = false
Exit Function
end if
if not fso.FileExists(dirstring + "" + "configenvironment.rb") then
msgbox "Folder " + dirstring + " is not a valid rails folder, aborting.", vbExclamation
CheckRailsDir = false
Exit Function
end if
CheckRailsDir = true
end function
'
'
sub SetRailsDir
Dim input, tempdir
input = ""
if RailsDir = "" then
tempdir = DefaultRailsDir
else
tempdir = RailsDir
end if
input = InputBox("Enter Rails Directory:",,tempdir)
if CheckRailsDir(input) then
RailsDir = input
msgbox "Set Rails directory to " & RailsDir, vbInformation
end if
end sub
'
'
sub RailsStop
if RailsDir = "" then
msgbox "Rails directory not set, aborting.", vbExclamation
Exit Sub
end if
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate Rubyexe
WshShell.SendKeys "^c"
Set WshShell = Nothing
end sub
'
'
sub RailsStart
if RailsDir = "" then
msgbox "Rails directory not set, aborting.", vbExclamation
Exit Sub
end if
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Rubyexe & " " & RailsDir & "scriptserver"
Set WshShell = Nothing
end sub
'
'
sub BrowseRails
if RailsDir = "" then
msgbox "Rails directory not set, aborting.", vbExclamation
Exit Sub
end if
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Browser + " http://localhost:3000"
Set WshShell = Nothing
end sub
'
'
' name "Init" is required, its called automatically during initialization to create menu items
sub Init
addMenuItem "Set Rails Dir", "Rails", "SetRailsDir"
addMenuItem "Start Rails Server", "Rails", "RailsStart"
addMenuItem "Stop Rails Server","Rails", "RailsStop"
addMenuItem "Webbrowse rails","Rails", "BrowseRails"
addMenuItem "Test Function", "Rails", "Test"
end sub
'
'
' end of file

Advertisements

One thought on “pspad editor vb script to help with ruby on rails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s