Micro framework
require "cuba"
Cuba.define do
on get do
on "hello" do
res.write "Hello world!"
end
on root do
res.redirect "/hello"
end
end
end
# unicorn server.ru -p 4001
require "./hello_world"
run Cuba
Cuba.define do
on get do
# /styles/basic.css
on "styles", extension("css") do |file|
res.write "Filename: #{file}" #=> "Filename: basic"
end
# /post/2011/02/16/hello
on "post/:y/:m/:d/:slug" do |y, m, d, slug|
res.write "#{y}-#{m}-#{d} #{slug}" #=> "2011-02-16 hello"
end
# /search?q=barbaz
on "search", param("q") do |query|
res.write "Searched for #{query}" #=> "Searched for barbaz"
end
end
end
Uso de Tilt para expandir los templates.
Soporte para:
require "cuba"
require "cuba/render"
require "haml"
Cuba.plugin(Cuba::Render)
Cuba.settings[:render][:template_engine] = "haml"
Cuba.define do
on "about" do
res.write partial("about")
end
on "home" do
res.write view("about")
end
end
Solo necesitamos hacer uso de sprockets
require 'cuba/assets'
Cuba.plugin Cuba::Assets
on 'assets/:path' do |path|
res.write asset(path)
end
/
└── assets
└── styles
├── app.css.scss
└── model
└── model.css.scss
Todo en cuba es simple
module MyOwnHelper
def markdown(str)
BlueCloth.new(str).to_html
end
end
Cuba.plugin MyOwnHelper
Los sistemas de seguridad de Cuba estan diponibles tambien como Modulos, asi como los sistemas de template.