Documentation for condition. Fixes GH #15.

This commit is contained in:
Konstantin Haase 2010-09-02 14:13:36 +02:00
parent 33affbf264
commit 726feeb4ee
1 changed files with 28 additions and 0 deletions

View File

@ -81,6 +81,8 @@ Or with a block parameter:
"Hello, #{c}!"
end
=== Conditions
Routes may include a variety of matching conditions, such as the user agent:
get '/foo', :agent => /Songbird (\d\.\d)[\d\/]*?/ do
@ -91,6 +93,32 @@ Routes may include a variety of matching conditions, such as the user agent:
# Matches non-songbird browsers
end
Other available conditions are `host_name` and `provides`:
get '/', :host_name => /^admin\./ do
"Admin Area, Access denied!"
end
get '/', :provides => 'html' do
haml :index
end
get '/', :provides => ['rss', 'atom', 'xml'] do
builder :feed
end
You can easily define your own conditions:
set(:probability) { |value| condition { rand <= value } }
get '/win_a_car', :probability => 0.1 do
"You won!"
end
get '/win_a_car' do
"Sorry, you lost."
end
== Static Files
Static files are served from the <tt>./public</tt> directory. You can specify