Skip to content
nesquena edited this page Sep 13, 2010 · 8 revisions

Introduction

sinatra_more comes equipped with code generators for Sinatra akin to the traditional Rails generators. The difference is that sinatra does not have ‘one true way’ for various libraries and tools so generators for sinatra must support a variety of popular tools for testing, mocking, templating, javascript and storing data.

Application Generator

The sinatra_more generator has full support for creating new applications using a variety of popular tools. The usage for the application generator is:

sinatra_gen <the_app_name> </path/to/create/app> --<component-name> <value>

In order to create a sinatra application using all the defaults, named DemoApp within a folder called ‘demo_app’ in the current directory:

sinatra_gen demo_app .

You can also configure which components you would like installed in your generated application:

sinatra_gen demo_app . --test=rspec --renderer=haml --mock=rr --orm datamapper

Note that ‘none’ can be specified for a component to skip generation:

sinatra_gen demo_app . --mock=none

In addition, you can use the component shortcuts for even quicker definitions:

sinatra_gen demo_app . -t=rspec -r=haml -m=rr -s=jquery -d=datamapper

The available components and their default options are listed below:

  • test: bacon (default), shoulda, rspec, testspec, riot
  • renderer: erb (default), haml
  • mock: mocha (default), rr
  • script: jquery (default), prototype, rightjs
  • orm: sequel (default), datamapper, mongomapper, activerecord

For more information on the specifics of getting started and configuring different components, check out the ORMComponents, TestComponents, RendererComponents, MockingComponents, and JavascriptComponents for details on what gems are required and how to use them properly.

The generator uses the bundler gem to resolve any application dependencies when the application is newly created. The necessary bundler command can be executed automatically through the generator with

$ sinatra_gen demo_app . --run_bundler # alias -b

or this can be done manually through executing command gem bundle in the terminal at the root of the generated application. If not executed manually, the bundling will be performed automatically the first time the application attempts to boot. Note that this command only has to be performed when the application is first generated or when the Gemfile is modified.

The generator framework within sinatra_more is highly extensible and additional components and tools can easily be added. This would be achieved through forking our project and reading through the code in /generators/sinatra_generator.rb and the setup instructions inside the relevant files within /generators/components/. We are happy to accept pull requests for additional component types not originally included (although helping us maintain them would also be appreciated).

Model Generator

Coming soon!

Routes Generator

Coming soon!

Migration Generator

Coming soon!