Sinatra: Classy web-development dressed in a DSL
Written on November 17, 2007 by ceefour

Sinatra is a new cool open-source DSL-driven web application framework!
This super-sexy DSL runs at lighting speed. It sits on top of Mongrel and was written to be thread-safe, sleek and tiny. And an entire web-application can be written and contained in one file (or a small collection of files)!
It’s super easy to use! Let’s create an app from scratch to demonstrate!
Install!
gem install sinatra -yUse!
- Create a file called lyrics.rb (or any name you like)
- Add
require 'rubygems' require 'sinatra'- Run (yes, with just ruby)
% ruby lyrics.rb == Sinata has taken the stage on port 4567!- Take a moment and view the default page localhost:4567. Go ahead and bask in it‘s glory.
- Notice:
- It didn‘t create any page to show you that default page (just a cool thing to see, that‘s all)
- There was nothing generated other than a log file
- Sinatra is a really cool name for a web-framework that‘s a DSL
- Modify lyrics.rb by adding:
get '/' do 'Hello World' end- Refresh (no need to restart Sinatra):
http://localhost:4567- Modify again (then refresh):
get '/' do <<-HTML <form action='/' method="POST"> <input type="text" name="name" /> <input type="submit" value="Say my name!" /> </form> HTML end post '/' do "Hello #{params[:name] || 'World'}!" end- Now you try: Use the Sinatra::Erb::EventContext or Sinatra::Haml::EventContext to do the same. Do them inline and as template files.
- Learn more cool stuff: see Sinatra::Dsl
- Create your own plugins!
- Create a ‘vendor’ directory in your app directory
- Lay it out like: myapp.rb : root
|- vendor | - plugin_name | - init.rb # load and hook here | - lib |- modules/classes here- Use it in your app!
For further details visit:
If you enjoyed this post Subscribe to our feed

Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)
December 28, 2007 at 8:47 am
[...] Sinatra: Classy web-development dressed in a DSL - Yet another quick way to bang together those web applications. [...]
February 1, 2008 at 6:28 pm
Controversy Continues Between Home Builders Association and Orlando Schools... Since the year 2000 when the Martinez Doctrine was promoted by the ...