Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update documentation and remove obsolete comments.

  • Loading branch information...
commit a6890c3a66645a469280566131df01600a22cb3b 1 parent 3ec24e8
@cyx cyx authored
View
4 README.markdown
@@ -1,7 +1,7 @@
Cuba
====
-Rum based microframework for web development.
+_n_. a microframework for web development.
![Cuba and Rum, by Jan Sochor](http://farm3.static.flickr.com/2619/4032103097_8324c6fecf.jpg)
@@ -13,7 +13,7 @@ Meet us on IRC: [#cuba.rb](irc://chat.freenode.net/#cuba.rb) on [freenode.net](h
Description
-----------
-Cuba is a microframework for web development heavily inspired by [Rum][rum],
+Cuba is a microframework for web development originally inspired by [Rum][rum],
a tiny but powerful mapper for [Rack][rack] applications.
It integrates many templates via [Tilt][tilt], and testing via
View
8 example/site.rb
@@ -4,11 +4,11 @@
Cuba.define do
on get do
- on path("dashboard") do
+ on "dashboard" do
res.write "Welcome to your Dashboard"
end
- on path("login") do
+ on "login" do
@greeting = "Hello World!"
res.write render("templates/form.erb")
end
@@ -19,7 +19,7 @@
end
on post do
- on path("login") do
+ on "login" do
on param("user") do |user|
res.write "Got #{user}"
end
@@ -29,4 +29,4 @@
end
end
end
-end
+end
View
32 lib/cuba/ron.rb
@@ -12,14 +12,6 @@ def redirect(target, status = 302)
end
end
-# Based on Rum: http://github.com/chneukirchen/rum
-#
-# Summary of changes
-#
-# 1. Only relevant captures are yielded.
-# 2. The #extname matcher is used more like #path.
-# 3. Miscellaneous coding style changes.
-#
module Cuba
class Ron
attr :env
@@ -42,7 +34,7 @@ def _call(env)
@res = Rack::Response.new
@matched = false
- catch(:rum_run_next_app) do
+ catch(:ron_run_next_app) do
instance_eval(&@blk)
@res.status = 404 unless @matched || !@res.empty?
@@ -90,15 +82,15 @@ def session
# res.write "GET"
# end
#
- # on get, path("signup") do
+ # on get, "signup" do
# res.write "Signup
# end
#
- # on path("user"), segment do |uid|
+ # on "user/:id" do |uid|
# res.write "User: #{uid}"
# end
#
- # on path("styles"), extname("css") do |file|
+ # on "styles", extname("css") do |file|
# res.write render("styles/#{file}.sass")
# end
#
@@ -120,7 +112,7 @@ def on(*args, &block)
# on true, false do
#
# # PATH_INFO=/user
- # on true, path("signup")
+ # on true, "signup"
return unless args.all? { |arg| match(arg) }
# The captures we yield here were generated and assembled
@@ -177,7 +169,7 @@ def match(matcher)
#
# @example
# # PATH_INFO=/style/app.css
- # on path("style"), extname("css") do |file|
+ # on "style", extname("css") do |file|
# res.write file # writes app
# end
def extname(ext = "\\w+")
@@ -189,7 +181,7 @@ def extname(ext = "\\w+")
#
# @example
# # POST with data like user[fname]=John&user[lname]=Doe
- # on path("signup"), param("user") do |atts|
+ # on "signup", param("user") do |atts|
# User.create(atts)
# end
def param(key, default = nil)
@@ -203,7 +195,7 @@ def header(key, default = nil)
# Useful for matching against the request host (i.e. HTTP_HOST).
#
# @example
- # on host("account1.example.com"), path("api") do
+ # on host("account1.example.com"), "api" do
# res.write "You have reached the API of account1."
# end
def host(hostname)
@@ -238,10 +230,10 @@ def default
# Syntatic sugar for providing HTTP Verb matching.
#
# @example
- # on get, path("signup") do
+ # on get, "signup" do
# end
#
- # on post, path("signup") do
+ # on post, "signup" do
# end
def get ; req.get? end
def post ; req.post? end
@@ -256,13 +248,13 @@ def delete ; req.delete? end
# run Cuba::Ron.new { on(default) { res.redirect(*args) }}
# end
#
- # on path("account") do
+ # on "account" do
# redirect "/login" unless session["uid"]
#
# res.write "Super secure account info."
# end
def run(app)
- throw :rum_run_next_app, app
+ throw :ron_run_next_app, app
end
end
end
View
2  test/integration.rb
@@ -52,7 +52,7 @@ def call(env)
Cuba.define do
on get do
- on path("hello") do
+ on "hello" do
res.write "Default"
end
end
View
30 test/match.rb
@@ -83,34 +83,4 @@
_, _, resp = Cuba.call(env)
assert_equal ["jdoe", "123"], resp.body
-end
-
-__END__
-test "benchmarks" do |env|
- require "benchmark"
-
- Cuba.define do
- on "posts/:id" do |id|
- res.write id
- end
- end
-
- t1 = Benchmark.realtime {
- 10_000.times { _, _, resp = Cuba.call(env) }
- }
-
- Cuba.reset!
-
- Cuba.define do
- on path("posts"), segment do |id|
- res.write id
- end
- end
-
- t2 = Benchmark.realtime {
- 10_000.times { _, _, resp = Cuba.call(env) }
- }
-
- puts t1
- puts t2
end
Please sign in to comment.
Something went wrong with that request. Please try again.