start 2
[sinatra.git] / README
blob50be282e94eae879980bd7e03dec9e3c1d66f309
1 Sinatra (C) 2007 By Blake Mizerany
3 = Classy web-development dressed in a DSL
5 == Install!
7   sudo gem install sinatra -y
9 == Use!
11 I'm going to move quick.  I'll let you drool at your own pace.
13 * Create a file called lyrics.rb (or any name you like)
15 * Add
16     require 'rubygems'
17     require 'sinatra'
19 * Run (yes, with just ruby)
20     % ruby lyrics.rb
21     == Sinata has taken the stage on port 4567!
23 * Take a moment and view the default page http://localhost:4567.  Go ahead and bask in it's glory.
25 * Notice:
26   * It didn't create any page to show you that default page (just a cool thing to see, that's all)
27   * There was nothing generated other than a log file
28   * Sinatra is a really cool name for a web-framework that's a DSL
30 * Modify lyrics.rb by adding:
31     get '/' do
32       'Hello World'
33     end
34   
35 * Refresh (no need to restart Sinatra):
36     http://localhost:4567
38 * Modify again (then refresh) -- And yes, this presentation logic can be quickly extracted to a template.. see below.
39     get '/' do
40       <<-HTML
41         <form action='/' method="POST">
42           <input type="text" name="name" />
43           <input type="submit" value="Say my name!" />
44         </form>
45       HTML
46     end
47   
48     post '/' do
49       "Hello #{params[:name] || 'World'}!"
50     end
52 * Test (lyrics_test.rb) -- We should be doing this first... for the purposes of this tutorial, we're doing it here
54  require 'sinatra/test/spec'
55  require 'lyrics'
56   
57  context "My app" do
58    specify "should have a form" do
59      get_it '/'
60      response.should.be.ok
61      body.scan('form').size.should.equal 1
63      post_it '/', :name => 'Sinatra'
64      response.should.be.ok
65      body.should.equal 'Hello Sinatra!'
66    end
67  end
69 For more test helpers see: Sinatra::Test::Methods and http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
71 * Now you try:
72   Use the Sinatra::Erb::EventContext or Sinatra::Haml::EventContext to do the same.  Do them inline and as template files.
74 * Learn more cool stuff:
75   see Sinatra::Dsl
77 * Create your own plugins!
78   1. Create a 'vendor' directory in your app directory
79   2. Lay it out like:
81      myapp.rb : root
82         |- vendor
83                      | - plugin_name
84                    | - init.rb  # load and hook here
85                    | - lib
86                          |- modules/classes here
88   3. Use it in your app!
90   see $SINATRA_GEM_ROOT/vendor/erb or $SINATRA_GEM_ROOT/vendor/erb for examples.
92 * Tell!
93 We would love to here what you're doing with Sinatra and any cool patches/features you would like.  (blake { dot } mizerany [ at ] gmail)
95 * Talk!
96 IRC (irc.freenode.com  #sinatra)
97 Mailing List (sinatrarb@googlegroups.com)
99 * Contribute
101 We're using git as our scm.. cuz.. it rocks.  You can get the latest source from http://repo.or.cz/w/sinatra.git
103 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.
105 It's probably going to happen.. you'll find a bug.  Please help by:
107 * Sending a message to sintrarb@googlegroups.com with BUG: at the start of the subject (I'm working on a better tracking system)
108 * Please send patches or pull requests to (blake { dot } mizerany [ at ] gmail) don't forget the dot com. ;)
110 == Thanks!
112 - Ezra Zygmuntowicz (http://brainspl.at) for answering all those random questions over IM and all the poached code
113 - Ditto to Chris Wanstrath (errtheblog.com) and helping me keep things simple, and some cool tricks
114 - Ari Lerner over at CitrusByte for ideas, code, and enthusiasm
115 - Christian Neukirchen for Rack (http://rack.rubyforge.org/)
116 - Koshi (http://www.songbirdnest.com/jkoshi/blog) here at POTI, Inc. for the Sinatra mark
117 - Pete Golibersuch for the hat logo
118 - John Philip Green (http://www.linkedin.com/in/johngreen) for motivation and evangelism
119 - The team here at songbirdnest.com for cool ideas