<http://forum.pspad.com/read.php?f=2&i=10784&t=10763> 
----------------------------------------------------------------

I'm posting the code here as well..


' 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.
'
' [EMAIL PROTECTED]
'
' 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 pspad\Script\VBScript 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

option explicit
const module_name = "Rails"
const module_ver = "0.1"
Dim DefaultRailsDir, Browser, Rubyexe
DefaultRailsDir = "c:\projects\ruby\rails"
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 + "\" + "config\environment.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 & "\script\server"
    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


-- 
PSPad freeware editor http://www.pspad.com

Reply via email to