I thought I’d share the base layout I use for the majority of my Sinatra applications. This base includes DataMapper, RSpec and haml. Please feel free to fork and improve upon if you wish. I borrowed some of the tasks/layout choices from Merb, so thanks :).
There is one other branch besides the master, this contains the same layout but includes authentication via Warden.
Install the needed gems:
sudo gem install sinatra haml rspec rack-test dm-core dm-more
Write some specs, add some controller actions and compliment them with some DataMapper models then run this:
rake db:automigrate ruby applicaiton.rb
Dependencies and configuration is done in the environment.rb file. DataMapper is setup to use sqlite3 by default. However you can set the environment variable DATABASE_URL to provide a production database. Tests will use the in-memory sqlite3 database so you don’t need to set that up.
Put all your controller actions in the applications.rb file, any helpers may go in here too and also any custom 404/error messages. For each actions the view is placed in the views directory.
All the static content belongs in the public directory in their appropriate sub-directories.
All the DataMapper models can be added to the models.rb file.
Finally, you can add your specs into the spec directory. Be sure to include spec_helper.rb. There is an example spec in the directory.
You can run specs using the rake task:
rake spec