Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/sinatra/sinatra
Browse files Browse the repository at this point in the history
  • Loading branch information
David Balatero committed Jun 10, 2009
2 parents 5fb4d19 + 4d94830 commit 6a68fb4
Show file tree
Hide file tree
Showing 55 changed files with 291 additions and 2,508 deletions.
9 changes: 9 additions & 0 deletions CHANGES
@@ -1,3 +1,12 @@
= 1.0 / unreleased

* Route handlers, before filters, templates, error mappings, and
middleware are now resolved dynamically up the inheritance hierarchy
when needed instead of duplicating the superclass's version when
a new Sinatra::Base subclass is created. This should fix a variety
of issues with extensions that need to add any of these things
to the base class.

= 0.9.2 / 2009-05-18

* This version is compatible with Rack 1.0. [Rein Henrichs]
Expand Down
52 changes: 51 additions & 1 deletion README.rdoc
@@ -1,6 +1,6 @@
= Sinatra

Sinatra is a DSL for quickly creating web-applications in Ruby with minimal
Sinatra is a DSL for quickly creating web applications in Ruby with minimal
effort:

# myapp.rb
Expand Down Expand Up @@ -470,6 +470,56 @@ recommended:
NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
are deprecated as of the 0.9.2 release.

== Sinatra::Base - Middleware, Libraries, and Modular Apps

Defining your app at the top-level works well for micro-apps but has
considerable drawbacks when building reuseable components such as Rack
middleware, Rails metal, simple libraries with a server component, or
even Sinatra extensions. The top-level DSL pollutes the Object namespace
and assumes a micro-app style configuration (e.g., a single application
file, ./public and ./views directories, logging, exception detail page,
etc.). That's where Sinatra::Base comes into play:

require 'sinatra/base'

class MyApp < Sinatra::Base
set :sessions, true
set :foo, 'bar'

get '/' do
'Hello world!'
end
end

The MyApp class is an independent Rack component that can act as
Rack middleware, a Rack application, or Rails metal. You can +use+ or
+run+ this class from a rackup +config.ru+ file; or, control a server
component shipped as a library:

MyApp.run! :host => 'localhost', :port => 9090

The methods available to Sinatra::Base subclasses are exactly as those
available via the top-level DSL. Most top-level apps can be converted to
Sinatra::Base components with two modifications:

* Your file should require +sinatra/base+ instead of +sinatra+;
otherwise, all of Sinatra's DSL methods are imported into the main
namespace.
* Put your app's routes, error handlers, filters, and options in a subclass
of Sinatra::Base.

+Sinatra::Base+ is a blank slate. Most options are disabled by default,
including the built-in server. See {Options and Configuration}[http://sinatra.github.com/configuration.html]
for details on available options and their behavior.

SIDEBAR: Sinatra's top-level DSL is implemented using a simple delegation
system. The +Sinatra::Application+ class -- a special subclass of
Sinatra::Base -- receives all :get, :put, :post, :delete, :before,
:error, :not_found, :configure, and :set messages sent to the
top-level. Have a look at the code for yourself: here's the
{Sinatra::Delegator mixin}[http://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1064]
being {included into the main namespace}[http://github.com/sinatra/sinatra/blob/master/lib/sinatra/main.rb#L25].

== Command line

Sinatra applications can be run directly:
Expand Down
21 changes: 1 addition & 20 deletions Rakefile
Expand Up @@ -2,35 +2,16 @@ require 'rake/clean'
require 'rake/testtask'
require 'fileutils'

task :default => [:test, :compat]
task :default => :test
task :spec => :test

# SPECS ===============================================================

task(:test) { puts "==> Running main test suite" }

Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
t.ruby_opts = ['-rubygems'] if defined? Gem
end

desc "Run < 0.9.x compatibility specs"
task :compat do
begin
require 'mocha'
require 'test/spec'
at_exit { exit 0 } # disable test-spec at_exit runner

puts "==> Running compat test suite"
Rake::TestTask.new(:compat) do |t|
t.test_files = FileList['compat/*_test.rb']
t.ruby_opts = ['-rubygems'] if defined? Gem
end
rescue LoadError
warn 'Skipping compat tests. mocha and/or test-spec gems not installed.'
end
end

# PACKAGING ============================================================

# Load the gemspec using the same limitations as github
Expand Down
282 changes: 0 additions & 282 deletions compat/app_test.rb

This file was deleted.

0 comments on commit 6a68fb4

Please sign in to comment.