Class Cuba
In: lib/cuba/render.rb
lib/cuba.rb
Parent: Object

Methods

accept   app   call   call   call!   default   define   delete   extension   get   halt   header   host   inherited   match   new   on   param   plugin   post   prototype   put   reset!   root   run   session   settings   settings   use  

Classes and Modules

Module Cuba::Render
Class Cuba::Response

Attributes

captures  [R] 
env  [R] 
req  [R] 
res  [R] 

Public Class methods

Public Instance methods

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

Syntactic sugar for providing catch-all matches.

@example

  on default do
    res.write "404"
  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

Access the root of the application.

@example

  # GET /
  on root do
    res.write "Home"
  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

[Validate]