mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Classy web-development dressed in a DSL (official / canonical repo)
| examples/hello | ||
| files | ||
| lib | ||
| site | ||
| test | ||
| vendor | ||
| .gitignore | ||
| CHANGELOG | ||
| LICENSE | ||
| Manifest | ||
| RakeFile | ||
| README | ||
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 http://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) -- And yes, this presentation logic can be quickly extracted to a template.. see below.
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
* Test (lyrics_test.rb) -- We should be doing this first... for the purposes of this tutorial, we're doing it here
require 'sinatra/test/spec'
require 'lyrics'
context "My app" do
specify "should have a form" do
get_it '/'
response.should.be.ok
body.scan('form').size.should.equal 1
post_it '/', :name => 'Sinatra'
response.should.be.ok
body.should.equal 'Hello Sinatra!'
end
end
For more test helpers see: Sinatra::Test::Methods and http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
* 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!
1. Create a 'vendor' directory in your app directory
2. Lay it out like:
myapp.rb : root
|- vendor
| - plugin_name
| - init.rb # load and hook here
| - lib
|- modules/classes here
3. 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)
* Talk!
IRC (irc.freenode.com #sinatra)
Mailing List (sinatrarb@googlegroups.com)
* Contribute
We're using git as our scm.. cuz.. it rocks. You can get the latest source from http://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 (http://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 (http://rack.rubyforge.org/)
- Koshi (http://www.songbirdnest.com/jkoshi/blog) here at POTI, Inc. for the Sinatra mark
- Pete Golibersuch for the hat logo
- John Philip Green (http://www.linkedin.com/in/johngreen) for motivation and evangelism
- The team here at songbirdnest.com for cool ideas