Fork me on GitHub

sinatra-gen

What

sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework.

For more information on sinatra, check out Sinatra’s homepage.

Why

Lots of generated code is sometimes not a great idea, but having a way to simply generate the basic files and structure of an app can save a lot of time and is really useful. A lot of people have different opinions about how to structure a sinatra app since there arent any implicit conventions like in Rails or Merb. With that in mind, I’ve tried to make sinatra-gen as flexible as possible while still doing a lot of the work for you.

Usage

Basic

Run:

$ sinatra-gen [appname] [actions] [options]

e.g.

$ sinatra-gen mysinatrapp get:/ post:/:id --vendor --init --test=shoulda --views=haml

Actions

For even faster app development you specify actions to include in your app when generating.

Actions are written out as

http_method:path

And are seperated by spaces. For example:

get:/ post:/:id put:/update/*

Will be added you your app as:

get '/' do
end

post '/:id' do
end

put '/update/*' do
end

It will also generate test stubs in the test framework of your choosing.

Middleware

You can specify middleware to include by passing the filename(s) or class name(s), seperated by commas.

$ sinatra-gen myapp --middleware=rack/flash,Rack::Cache

Will place both the ‘require’ and ‘use’ statements in your app.

require 'rack/flash'
require 'rack/cache'

#...

use Rack::Flash
use Rack::Cache

Options

(can also be obtained by running sinatra-gen with no arguments):

    -v, --version                    Show the sinatra-gen version number and quit.
    -d, --vendor                     Extract the latest sinatra to vendor/sinatra
        --tiny                       Only create the minimal files.
        --init                       Initialize a git repository
        --heroku                     Create a Heroku app (also runs 'git init').
 Optionally, specify the path to the heroku bin
        --cap                        Adds config directory with basic capistrano deploy.rb
        --scripts                    Install the rubigen scripts (script/generate, script/destroy)
        --test=test_framework        Specify your testing framework (bacon (default)/rspec/spec/shoulda/test)
        --views=view_framework       Specify your view framework (haml (default)/erb/builder)
        --middleware=rack-middleware Specify Rack Middleware to be required and included (comma delimited)
        --vegas, --bin=[bin_name]    Create an executable bin using Vegas. Pass an optional bin_name

The --tiny option will create no directories. Just an app.rb, a Rakefile, and a config.ru (Rackup file)

Dependencies

sinatra-gen requires:

  • rubygems >= 1.3.1
  • rubigen = 1.5.2
  • sinatra >= 0.9.4
  • rack-test >= 0.4.1

If you want to use the --init option, you need to have git installed and on your path.

To use the --heroku option you need the heroku gem as well as a heroku account.

Installing

sudo gem install sinatra-gen
        

Or directly from github:

sudo gem install quirkey-sinatra-gen -s http://gems.github.com
        

Github in thier infinite awesomeness also lets you download the source in multiple formats.

Bugs/Feature Requests

The full and most up to date source is at github:

http://github.com/quirkey/sinatra-gen/

You can clone or fork from there to fix or break the code.

I’m happy to take feature requests/bug reports. Just email me (contact below) or message me on github.

License

This code is free to use under the terms of the MIT license.

Contact

Feel free to email me at aaron at quirkey dot com.

Please check out my blog.

If you like or use this library – I don’t want donations – but you can recommend me on workingwithrails.com or hire me to work on your next project.