Created
January 19, 2013 19:22
-
-
Save RohitRox/4574531 to your computer and use it in GitHub Desktop.
Simple bash function to generate sinatra app skeleton. USAGE: $ sinatra app_name; shotgun
This file contains 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
function sinatra { | |
if [ "$1" == "" ]; then | |
echo "Usage:" | |
echo "'sinatra app_name' to create a new Sinatra app skeleton"; | |
else | |
if [ ! -d "$1" ]; then | |
echo "Generating your app ... " | |
mkdir $1 | |
mkdir $1/views; | |
mkdir $1/public; | |
mkdir $1/public/images; | |
mkdir $1/public/stylesheets; | |
mkdir $1/public/javsscripts; | |
cd $1 | |
echo "..." | |
cat >> app.rb <<EOF | |
# encoding: utf-8 | |
require 'rubygems' | |
require 'sinatra' | |
class App < Sinatra::Base | |
get '/' do | |
erb :index | |
end | |
end | |
EOF | |
cat >> config.ru <<EOF | |
require 'rubygems' | |
require 'bundler' | |
require "./app" | |
run App | |
EOF | |
cat >> Gemfile <<EOF | |
source :rubygems | |
gem 'sinatra' | |
gem 'shotgun' | |
EOF | |
cd views | |
cat >> index.erb <<EOF | |
<h1 id="heading">It works!<h1> | |
EOF | |
cat >> layout.erb <<EOF | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Simple Sinatra App Skeleton</title> | |
</head> | |
<body> | |
<%= yield %> | |
</body> | |
</html> | |
EOF | |
cd .. | |
echo "sinatra app successfully created." | |
echo "Executing bundle" | |
bundle | |
echo "You are here '$PWD'" | |
echo "Your sinatra app skeleton tree:" | |
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' | |
echo "run 'shotgun' to run server" | |
else | |
echo "Error creating the application: Folder named $1 already exists in your current directory." ; | |
fi; | |
fi; | |
} |
Author
RohitRox
commented
May 24, 2013
- copy this script to your .bashrc or .zshrc
- reload your shell
- sinatra command is now available in your terminal
- sinatra app_name # generates, bundles and cd to app, and show your app directory tree (cool)
- shotgun # runs server localhost:9393
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment