Hello Sinatra is a barebones, classic-style Sinatra application that utilizes Ruby 1.9.x, Bundler for managing dependencies, Slim for templates, Compass (Sass) for CSS, and MiniTest::Spec for tests.
It is meant to be a blank slate that will give you a head start when developing your own application with this specific technology stack.
Open up your favorite terminal emulator and...
$ git clone git://github.com/elasticdog/hello-sinatra.git
$ cd hello-sinatra/
$ bundle install
$ ruby my_app.rb
That will launch the app using Thin at http://localhost.com:4567/, so open up a browser and bask in all the "Hello world!" glory. You can press Ctrl-C
in the terminal to shut things down and get back to the command prompt.
To run the included tests:
$ rake test # run tests normally $ rake test TESTOPTS="-v" # run in verbose mode
Assuming you want add a bit more functionality than "Hello world!", here's how things are organized...
hello-sinatra/
├── spec/
│ ├── my_app_spec.rb
│ └── spec_helper.rb
├── views/
│ ├── stylesheets/
│ │ └── style.scss
│ ├── index.slim
│ └── layout.slim
├── .gitignore
├── Gemfile
├── Gemfile.lock
├── Guardfile
├── LICENSE
├── README.md
├── Rakefile
├── config.ru
└── my_app.rb
Make your application changes in my_app.rb
, template changes under the views/
directory, stylesheet changes under views/stylesheets/
, and test changes under the spec/
directory. Create a top-level lib/
directory for any additional Ruby modules you want to include, and a public/
directory for static files.
When developing a new Sinatra app, you don't want to be stuck manually reloading WEBrick and running rake test
every time you make a change. Luckily, there are ways to automate reloading the appropriate services whenever you save your app.
To automatically reload your development server, there are a couple of possibilities...if you're on OS X, the Pow project makes this process incredibly straight forward (more so when adding the powder
gem on top as a command-line wrapper); or you can use the shotgun
gem to fork and reload the server on every request.
$ shotgun config.ru
To automatically run your tests, you can use the guard
gem along with the included Guardfile
. This is similar to using ZenTest/autotest, but guard gives you a bit more flexibility.
$ guard
There are a couple of recepies defined in the Guardfile
, feel free to add your own!
Have ideas on how to make Hello Sinatra better? Great! Just fork the project, create a new branch, make your changes, push them back, and send a pull request.
Copyright © 2011, Aaron Bull Schaefer. Hello Sinatra is distributed under the MIT License.