ecrr8q
Last Updated: February 25, 2016
·
1.496K
· kgrz
Ab74528b8223851cd7b546beec220fdc

Sinatra.rake

Fork the gist here

~/.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 in a specified directory"
task :create_sinatra_in 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

Say Thanks
Respond