Sinatra (C) 2007 By Blake Mizerany
Classy web-development dressed in a DSL
Install!
sudo gem install sinatra -y
Use!
I‘m going to move quick. I‘ll let you drool at your own pace.
- 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!
see $SINATRA_GEM_ROOT/vendor/erb or $SINATRA_GEM_ROOT/vendor/erb for
examples.
- Tell!
We would love to here what you‘re doing with Sinatra and any cool patches/features
you would like. (blake { dot } mizerany [ at ] gmail)
IRC (irc.freenode.com sinatra) Mailing List (sinatrarb@googlegroups.com)
We‘re using git as our scm.. cuz.. it rocks. You can get the latest
source from repo.or.cz/w/sinatra.git
NOTE: You can also get tar‘d snapshots of each commit there too. So
technically you don‘t need git to get the latest code.
It‘s probably going to happen.. you‘ll find a bug. Please help
by:
- Sending a message to sintrarb@googlegroups.com with BUG: at the start of
the subject (I‘m working on a better tracking system)
- Please send patches or pull requests to (blake { dot } mizerany [ at ]
gmail) don‘t forget the dot com. ;)
Thanks!
- Ezra Zygmuntowicz (brainspl.at) for
answering all those random questions over IM and all the poached code
- Ditto to Chris Wanstrath (errtheblog.com) and helping me keep things
simple, and some cool tricks
- Ari Lerner over at CitrusByte for ideas, code, and enthusiasm
- Christian Neukirchen for Rack (rack.rubyforge.org/)
- Koshi (www.songbirdnest.com/jkoshi/blog)
here at POTI, Inc. for the Sinatra
mark
- Pete Golibersuch for the hat logo
- John Philip Green (www.linkedin.com/in/johngreen)
for motivation and evangelism
- The team here at songbirdnest.com for cool ideas