Class | Cuba |
In: |
lib/cuba/version.rb
lib/cuba.rb |
Parent: | Object |
VERSION | = | "2.2.1" |
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
Render any type of template file supported by Tilt.
@example
# Renders home, and is assumed to be HAML. render("home.haml") # Renders with some local variables render("home.haml", site_name: "My Site") # Renders with HAML options render("home.haml", {}, ugly: true, format: :html5) # Renders in layout render("layout.haml") { render("home.haml") }