-
-
Save runemadsen/3624189 to your computer and use it in GitHub Desktop.
new_sinatra_app.rb
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 | |
require 'fileutils' | |
install_root = File.expand_path(File.dirname(__FILE__)) | |
if !ARGV[0] | |
puts "ERROR: You must supply the name of the app you want to create. Like this:" | |
puts "./new_sinatra_app my_app" | |
exit 1 | |
end | |
nid = install_root.split("/")[2] | |
app_name = ARGV[0] | |
app_name.gsub!(" ", "_") | |
puts "Creating new app: #{app_name}..." | |
puts "install_root: #{install_root}" | |
puts "NETID: #{nid}" | |
puts | |
puts | |
puts "Creating folder structure..." | |
puts | |
puts "creating public directory" | |
# create folder structure + always_retart.txt | |
FileUtils.mkdir_p "#{install_root}/#{app_name}/public" | |
puts "creating tmp directory" | |
FileUtils.mkdir_p "#{install_root}/#{app_name}/tmp" | |
puts "creating always_restart.txt " | |
FileUtils.touch "#{install_root}/#{app_name}/tmp/always_restart.txt" | |
puts "creating config.ru" | |
# install config.ru | |
File.open("#{install_root}/#{app_name}/config.ru", "w") do |f| | |
f.write <<-BLAH | |
require File.dirname(__FILE__) + '/app.rb' | |
before do | |
s = request.path_info | |
s[/^\\/~(\\w)+(\\d)+\\/sinatra\\/[^\\/|?]+/i] = "" | |
request.path_info = s | |
end | |
run Sinatra::Application | |
BLAH | |
end | |
puts "creating .htaccess file" | |
# install .htaccess | |
File.open("#{install_root}/#{app_name}/.htaccess", "w") do |f| | |
f.write <<-BLAH | |
PassengerEnabled on | |
RackBaseURI /sinatra | |
PassengerAppRoot #{install_root}/#{app_name} | |
RackEnv development | |
BLAH | |
end | |
puts | |
puts "creating app.rb" | |
# populate default app | |
File.open("#{install_root}/#{app_name}/app.rb", "w") do |f| | |
f.write <<-BLAH | |
require 'sinatra' | |
# Main route | |
get '/' do | |
"Hello" | |
end | |
BLAH | |
end | |
puts "checking for sinatra directory in public_html" | |
FileUtils.mkdir_p "/home/#{nid}/public_html/sinatra" | |
puts "installing symlink" | |
FileUtils.ln_s "#{install_root}/#{app_name}", "/home/#{nid}/public_html/sinatra/#{app_name}" | |
puts | |
puts "done!" | |
puts "edit you new app here:" | |
puts "#{install_root}/sinatra/#{app_name}/" | |
puts "and see it on the web here:" | |
puts "http://itp.nyu.edu/~#{nid}/sinatra/#{app_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment