In November 2007, we casually mentioned a new Ruby webapp library called Sinatra. It took a year to capture the imagination of the Ruby community as a whole and we eventually covered it in more depth but today we’re proud to (exclusively) announce that Sinatra has today reached its landmark 1.0 release!
Impromptu release party in the official #sinatra channel on irc.freenode.net, anyone?
Sinatra is well known in the Ruby community for providing developers with a simple way to put together Web apps big and small. The canonical ultra-simple example:
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end
Sinatra’s lead developers — Ryan Tomayko, Simon Rozet, and Blake Mizerany — have done a great job, along with about 50 other contributors, to produce a slick and powerful Web application DSL for Rubyists. Their ideas have even inspired similar frameworks in other languages (such as Sammy in JavaScript). Satish Talim put together a great piece, 20+ Rubyists are using Sinatra – Do you?, last year that got a good feel for how Sinatra’s being used for Web apps both big and small by a collection of Rubyists.
What’s New?
As an avid user of Sinatra 0.9, I asked Blake Mizerany what the biggest changes were going to 1.0:
I think the biggest changes are what we cleaned up. Tilt is a great new under-the-hood addition. Sinatra has matured; we’re done messing around. It’s super solid. The extension API has matured to something really killer. Extensions are ridiculously simple to create now – you can easily install helper methods, DSL methods, and install new routes on apps, and the user need only
require 'sinatra/your-extension'– that’s it.
Unsurprisingly, the official changelog also provides useful information to existing Sinatra developers.
A more significant longer-term change for Sinatra over the past year has been in how it integrates with Rack. In Sinatra Rack And Middleware, Ben Schwarz looks at how Sinatra interacts with Rack and how you can use Rack’s middleware and multi-application features with Sinatra. A key aspect of this is the ability to produce “modular” Sinatra applications by subclassing Sinatra::Base to separate discrete applications or application portions:
require 'rubygems'
require 'sinatra/base'
class MyApp < Sinatra::Base
get '/' do
"Hello world!"
end
end
And then, in a Rackup file:
require 'my_app'
run MyApp
Installing and Trying Sinatra
If you’re not yet using Sinatra and want to give it a quick try, you can install it with RubyGems:
gem install sinatra
Put the following basic example into a file, say example.rb:
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end
Then run the Ruby file in the usual way, and a request to http://localhost:4567/hi should get you a “Hello World!” response.
Learn More Online and on IRC
The examples shown above are as basic as Sinatra gets, but it goes a lot deeper than that (such as embedding Sinatra apps inside Rails apps) and the Sinatra Web site has some great code examples of where you can go next. There’s also solid documentation available and if you want to take a look at lots of existing Sinatra projects to get a feel for the patterns and techniques involved, there’s a great list of Sinatra apps and extensions too.
Lastly, if you’re interested in asking questions about Sinatra or just hanging out with Sinatra’s developers and users, head along to the #sinatra channel on irc.freenode.net. There’s usually between 50-100 people hanging out there.
Похожие записи
Нет комментариев
Оставить комментарий или два