Permalink
Browse files

Documentation for condition. Fixes GH #15.

  • Loading branch information...
1 parent 33affbf commit 726feeb4ee0e0f0acbe3f68d4065b322ac69ed7c @rkh rkh committed Sep 2, 2010
Showing with 28 additions and 0 deletions.
  1. +28 −0 README.rdoc
View
@@ -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

0 comments on commit 726feeb

Please sign in to comment.