Created
April 8, 2012 20:56
-
-
Save erikeldridge/2339826 to your computer and use it in GitHub Desktop.
Initialize heroku-ready sinatra/mustache app
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
echo -e "\n$0: Creating project\n" | |
app_name=`heroku apps:create | ruby -e 'ARGF.read =~ /([\w-]+)\.herokuapp/; puts $1'` | |
git clone [email protected]:$app_name.git | |
cd $app_name | |
echo -e "\n$0: Creating .rvmrc\n" | |
echo "rvm ruby-1.8.7-p330" > .rvmrc | |
rvm rvmrc load | |
echo -e "\n$0: Installing gems\n" | |
gem install bundler | |
read -r -d '' gemfile <<'END' | |
source 'http://rubygems.org' | |
gem 'sinatra' | |
gem 'shotgun' | |
gem 'mustache' | |
END | |
echo -e "$gemfile" > Gemfile | |
bundle | |
echo -e "\n$0: Creating config.ru\n" | |
read -r -d '' config <<'END' | |
require 'app' | |
run Sinatra::Application | |
END | |
echo -e "$config" > config.ru | |
echo -e "\n$0: Creating app.rb\n" | |
read -r -d '' app <<'END' | |
require 'sinatra' | |
require 'mustache/sinatra' | |
require 'views/layout' # initialize Sinatra::Application::Views | |
set :mustache, { :templates => './views', :views => './views' } | |
get '/' do | |
mustache :home | |
end | |
END | |
echo "$app" > app.rb | |
echo -e "\n$0: Create views & public dirs" | |
for name in "views public" | |
do | |
mkdir $name | |
done | |
echo -e "\n$0: Create layout view\n" | |
read -r -d '' layout_view <<'END' | |
# Ref: https://github.com/mislav/explain-ruby | |
module Sinatra::Application::Views | |
class Layout < Mustache | |
end | |
end | |
END | |
echo "$layout_view" > views/layout.rb | |
echo -e "\n$0: Create layout template\n" | |
read -r -d '' layout_template <<'END' | |
<!DOCTYPE html> | |
<head> | |
<meta http-equiv="content-type" content="text/html;charset=utf-8"> | |
<title>{{ title }}</title> | |
<link rel="stylesheet" media="all" href="/stylesheet.css"> | |
</style> | |
</head> | |
<body> | |
{{{ yield }}} | |
</body> | |
END | |
echo "$layout_template" > views/layout.mustache | |
echo -e "\n$0: Create home view\n" | |
read -r -d '' home_view <<'END' | |
module Sinatra::Application::Views | |
class Home < Layout | |
def title; 'home' end | |
end | |
end | |
END | |
echo "$home_view" > views/home.rb | |
echo -e "\n$0: Create home template\n" | |
read -r -d '' template <<'END' | |
:) | |
END | |
echo "$template" > views/home.mustache | |
echo -e "\n$0: Create stylesheet\n" | |
read -r -d '' css <<'END' | |
body { | |
color: green | |
} | |
END | |
echo "$css" > public/stylesheet.css | |
echo -e "\n$0: Committing\n" | |
git add .rvmrc Gemfile* config.ru app.rb views public | |
git commit -m 'Create app' | |
echo -e "\n$0: Success! \n\nApp created in ./$app_name\n\nRun the app via shotgun: $ shotgun\n\nHappy hacking\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment