Class | Cuba |
In: |
lib/cuba.rb
lib/cuba/render.rb |
Parent: | Object |
captures | [R] | |
env | [R] | |
req | [R] | |
res | [R] |
If you want to match against the HTTP_ACCEPT value.
@example
# HTTP_ACCEPT=application/xml on accept("application/xml") do # automatically set to application/xml. res.write res["Content-Type"] end
A matcher for files with a certain extension.
@example
# PATH_INFO=/style/app.css on "style", extension("css") do |file| res.write file # writes app end
Syntatic sugar for providing HTTP Verb matching.
@example
on get, "signup" do end on post, "signup" do end
Useful for matching against the request host (i.e. HTTP_HOST).
@example
on host("account1.example.com"), "api" do res.write "You have reached the API of account1." end
The heart of the path / verb / any condition matching.
@example
on get do res.write "GET" end on get, "signup" do res.write "Signup end on "user/:id" do |uid| res.write "User: #{uid}" end on "styles", extension("css") do |file| res.write render("styles/#{file}.sass") end
Used to ensure that certain request parameters are present. Acts like a precondition / assertion for your route.
@example
# POST with data like user[fname]=John&user[lname]=Doe on "signup", param("user") do |atts| User.create(atts) end
If you want to halt the processing of an existing handler and continue it via a different handler.
@example
def redirect(*args) run Cuba.new { on(default) { res.redirect(*args) }} end on "account" do redirect "/login" unless session["uid"] res.write "Super secure account info." end