Created
April 15, 2012 20:57
-
-
Save jonathanbeebe/2394775 to your computer and use it in GitHub Desktop.
New Rails + Sublime Text 2 Project (Script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# newrailsproject.rb | |
# | |
# Description: | |
# Easily create a new Rails project and Sublime Text 2 project file. | |
# | |
# By Jonathan Beebe. MIT License. | |
# | |
# Syntax: ruby newrailsproject.rb PROJECT_NAME BASE_PATH [sublime_project_basepath] | |
# | |
# requires: | |
# * rails (gem install rails) | |
# * json (gem install json) | |
project_name, base_path, sublime_project_path = ARGV | |
def help | |
puts <<-HELPFILE | |
Usage: | |
ruby newrailsproject.rb <NAME> <BASEPATH> [sublime_project_basepath] | |
Options: | |
-h [--help] # show this help information | |
HELPFILE | |
Process.exit(0) | |
end | |
# create a Sublime Text 2 project (which is JSON format) | |
def sublime_project( name, base_path, project_path ) | |
require 'json' | |
project = { "folders" => [{ "path" => base_path }] } | |
filename = project_path + '/' + name.delete(' ') + ".sublime-project" | |
sublime_project = File.open( filename , 'w' ) | |
sublime_project.write( project.to_json ) | |
sublime_project.close | |
end | |
# creates a new rails app (via "rails new ...") | |
def new_rails( name, base ) | |
return if not name or not base | |
name = name.delete(' ') # removes all spaces from string | |
exec "rails new #{base}/#{name}" | |
end | |
# check script arguments; show help if name and/or basepath is not provided | |
if project_name == "-h" or project_name == "--help" | |
help | |
elsif not project_name | |
project_name = "railsapp" | |
end | |
if not base_path | |
help | |
else | |
# make sure path does not end with a slash '/' | |
if base_path[-1] == '/' | |
base_path.pop | |
end | |
end | |
sublime_project( project_name, base_path + '/' + project_name, sublime_project_path || base_path ) | |
new_rails( project_name, base_path ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment