Skip to content

Instantly share code, notes, and snippets.

@kgrz
Last active December 16, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgrz/5413995 to your computer and use it in GitHub Desktop.
Save kgrz/5413995 to your computer and use it in GitHub Desktop.
Create a directory structure for Sinatra using rake task. Not the most robust implementation but works.
# ~/.rake is your global rake directory. Rake knows the tasks you write there.
# Create a rake file, say, sinatra.rake
desc "Create a directory structure for Sinatra classic app"
task :create_sinatra do
sh "mkdir public"
sh "touch app.rb"
sh "mkdir public/js"
sh "mkdir public/css"
sh "mkdir public/images"
end
# The description is mandatory for global rake tasks.
# And then, "cd" into your app directory and run:
rake -g create_sinatra
# or
rake --system create_sinatra
# Optionally, you can specify a directory name. The script would be:
# (Hattip: http://itshouldbeuseful.wordpress.com/2011/11/07/passing-parameters-to-a-rake-task/)
desc "Create a directory structure for Sinatra classic app"
task :create_sinatra do
dir = ARGV.count > 2 ? ARGV.last : "."
sh "mkdir #{dir}" unless dir == "."
sh "mkdir #{dir}/public"
sh "touch #{dir}/app.rb"
sh "mkdir #{dir}/public/js"
sh "mkdir #{dir}/public/css"
sh "mkdir #{dir}/public/images"
end
# and run it with
rake -g create_sinatra # which creates a dir structure in the current directory
# or
rake -g create_sinatra 'myapp/appfolder' # which will create the structure under 'myapp/appfolder' dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment