cuba 1.0.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +23 -14
- data/cuba.gemspec +5 -5
- data/lib/cuba/ron.rb +27 -76
- data/lib/cuba/version.rb +1 -1
- data/test/captures.rb +24 -9
- data/test/{extension.rb → extname.rb} +3 -3
- data/test/host.rb +29 -0
- data/test/integration.rb +3 -3
- data/test/match.rb +86 -0
- data/test/number.rb +5 -5
- data/test/on.rb +12 -0
- data/test/path.rb +20 -6
- data/test/run.rb +2 -2
- data/test/segment.rb +3 -3
- metadata +11 -9
data/README.markdown
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
Cuba
|
2
2
|
====
|
3
3
|
|
4
|
-
|
4
|
+
_n_. a microframework for web development.
|
5
5
|
|
6
6
|
![Cuba and Rum, by Jan Sochor](http://farm3.static.flickr.com/2619/4032103097_8324c6fecf.jpg)
|
7
7
|
|
8
|
+
Community
|
9
|
+
---------
|
10
|
+
|
11
|
+
Meet us on IRC: [#cuba.rb](irc://chat.freenode.net/#cuba.rb) on [freenode.net](http://freenode.net/)
|
12
|
+
|
8
13
|
Description
|
9
14
|
-----------
|
10
15
|
|
11
|
-
Cuba is a microframework for web development
|
16
|
+
Cuba is a microframework for web development originally inspired by [Rum][rum],
|
12
17
|
a tiny but powerful mapper for [Rack][rack] applications.
|
13
18
|
|
14
19
|
It integrates many templates via [Tilt][tilt], and testing via
|
@@ -32,7 +37,7 @@ Here's a simple application:
|
|
32
37
|
|
33
38
|
Cuba.define do
|
34
39
|
on get do
|
35
|
-
on
|
40
|
+
on "hello" do
|
36
41
|
res.write "Hello world!"
|
37
42
|
end
|
38
43
|
|
@@ -68,28 +73,33 @@ Here's an example showcasing how different matchers work:
|
|
68
73
|
|
69
74
|
Cuba.define do
|
70
75
|
|
76
|
+
# /
|
77
|
+
on "" do
|
78
|
+
res.write "Home"
|
79
|
+
end
|
80
|
+
|
71
81
|
# /about
|
72
|
-
on
|
82
|
+
on "about" do
|
73
83
|
res.write "About"
|
74
84
|
end
|
75
85
|
|
76
86
|
# /styles/basic.css
|
77
|
-
on
|
87
|
+
on "styles", extname("css") do |file|
|
78
88
|
res.write "Filename: #{file}" #=> "Filename: basic"
|
79
89
|
end
|
80
90
|
|
81
91
|
# /post/2011/02/16/hello
|
82
|
-
on
|
92
|
+
on "post/:y/:m/:d/:slug" do |y, m, d, slug|
|
83
93
|
res.write "#{y}-#{m}-#{d} #{slug}" #=> "2011-02-16 hello"
|
84
94
|
end
|
85
95
|
|
86
96
|
# /username/foobar
|
87
|
-
on
|
97
|
+
on "username/:username" do |username|
|
88
98
|
|
89
99
|
user = User.find_by_username(username) # username == "foobar"
|
90
100
|
|
91
101
|
# /username/foobar/posts
|
92
|
-
on
|
102
|
+
on "posts" do
|
93
103
|
|
94
104
|
# You can access `user` here, because the `on` blocks
|
95
105
|
# are closures.
|
@@ -97,18 +107,18 @@ Here's an example showcasing how different matchers work:
|
|
97
107
|
end
|
98
108
|
|
99
109
|
# /username/foobar/following
|
100
|
-
on
|
110
|
+
on "following" do
|
101
111
|
res.write user.following.size #=> "1301"
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
105
115
|
# /search?q=barbaz
|
106
|
-
on
|
116
|
+
on "search", param("q") do |query|
|
107
117
|
res.write "Searched for #{query}" #=> "Searched for barbaz"
|
108
118
|
end
|
109
119
|
|
110
|
-
on post
|
111
|
-
on
|
120
|
+
on post do
|
121
|
+
on "login"
|
112
122
|
|
113
123
|
# POST /login, user: foo, pass: baz
|
114
124
|
on param("user"), param("pass") do |user, pass|
|
@@ -124,7 +134,6 @@ Here's an example showcasing how different matchers work:
|
|
124
134
|
end
|
125
135
|
end
|
126
136
|
|
127
|
-
|
128
137
|
That's it, you can now run `rackup` and enjoy what you have just created.
|
129
138
|
|
130
139
|
To read more about testing, check the documentation for [Cutest][cutest] and
|
@@ -133,4 +142,4 @@ To read more about testing, check the documentation for [Cutest][cutest] and
|
|
133
142
|
Installation
|
134
143
|
------------
|
135
144
|
|
136
|
-
$ gem install cuba
|
145
|
+
$ gem install cuba
|
data/cuba.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cuba"
|
3
|
-
s.version = "
|
3
|
+
s.version = "2.0.0.rc1"
|
4
4
|
s.summary = "Rum based microframework for web applications."
|
5
5
|
s.description = "Cuba is a light wrapper for Rum, a microframework for Rack applications."
|
6
6
|
s.authors = ["Michel Martens"]
|
7
7
|
s.email = ["michel@soveran.com"]
|
8
8
|
s.homepage = "http://github.com/soveran/cuba"
|
9
|
-
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cuba/ron.rb", "lib/cuba/test.rb", "lib/cuba/version.rb", "lib/cuba.rb", "cuba.gemspec", "test/accept.rb", "test/captures.rb", "test/
|
9
|
+
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cuba/ron.rb", "lib/cuba/test.rb", "lib/cuba/version.rb", "lib/cuba.rb", "cuba.gemspec", "test/accept.rb", "test/captures.rb", "test/extname.rb", "test/helper.rb", "test/host.rb", "test/integration.rb", "test/match.rb", "test/number.rb", "test/on.rb", "test/path.rb", "test/run.rb", "test/segment.rb"]
|
10
10
|
s.add_dependency "rack", "~> 1.2"
|
11
|
-
s.add_dependency "tilt", "~> 1.
|
12
|
-
s.add_development_dependency "cutest", "~> 0
|
13
|
-
s.add_development_dependency "capybara", "~> 0.
|
11
|
+
s.add_dependency "tilt", "~> 1.2"
|
12
|
+
s.add_development_dependency "cutest", "~> 1.0"
|
13
|
+
s.add_development_dependency "capybara", "~> 0.4"
|
14
14
|
end
|
data/lib/cuba/ron.rb
CHANGED
@@ -12,14 +12,6 @@ class Rack::Response
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
# Based on Rum: http://github.com/chneukirchen/rum
|
16
|
-
#
|
17
|
-
# Summary of changes
|
18
|
-
#
|
19
|
-
# 1. Only relevant captures are yielded.
|
20
|
-
# 2. The #extension matcher is used more like #path.
|
21
|
-
# 3. Miscellaneous coding style changes.
|
22
|
-
#
|
23
15
|
module Cuba
|
24
16
|
class Ron
|
25
17
|
attr :env
|
@@ -42,7 +34,7 @@ module Cuba
|
|
42
34
|
@res = Rack::Response.new
|
43
35
|
@matched = false
|
44
36
|
|
45
|
-
catch(:
|
37
|
+
catch(:ron_run_next_app) do
|
46
38
|
instance_eval(&@blk)
|
47
39
|
|
48
40
|
@res.status = 404 unless @matched || !@res.empty?
|
@@ -90,15 +82,15 @@ module Cuba
|
|
90
82
|
# res.write "GET"
|
91
83
|
# end
|
92
84
|
#
|
93
|
-
# on get,
|
85
|
+
# on get, "signup" do
|
94
86
|
# res.write "Signup
|
95
87
|
# end
|
96
88
|
#
|
97
|
-
# on
|
89
|
+
# on "user/:id" do |uid|
|
98
90
|
# res.write "User: #{uid}"
|
99
91
|
# end
|
100
92
|
#
|
101
|
-
# on
|
93
|
+
# on "styles", extname("css") do |file|
|
102
94
|
# res.write render("styles/#{file}.sass")
|
103
95
|
# end
|
104
96
|
#
|
@@ -120,14 +112,12 @@ module Cuba
|
|
120
112
|
# on true, false do
|
121
113
|
#
|
122
114
|
# # PATH_INFO=/user
|
123
|
-
# on true,
|
124
|
-
args.
|
125
|
-
return unless arg == true || arg != false && arg.call
|
126
|
-
end
|
115
|
+
# on true, "signup"
|
116
|
+
return unless args.all? { |arg| match(arg) }
|
127
117
|
|
128
118
|
# The captures we yield here were generated and assembled
|
129
119
|
# by evaluating each of the `arg`s above. Most of these
|
130
|
-
# are carried out by #
|
120
|
+
# are carried out by #consume.
|
131
121
|
yield *captures
|
132
122
|
|
133
123
|
# At this point, we've successfully matched with some corresponding
|
@@ -152,35 +142,6 @@ module Cuba
|
|
152
142
|
end
|
153
143
|
private :try
|
154
144
|
|
155
|
-
# Probably the most useful helper for writing matchers.
|
156
|
-
#
|
157
|
-
# @example
|
158
|
-
# # matches PATH_INFO=/signup
|
159
|
-
# on path("signup") do
|
160
|
-
#
|
161
|
-
# # matches PATH_INFO=/user123
|
162
|
-
# on path("user(\\d+)") do |uid|
|
163
|
-
#
|
164
|
-
# # matches PATH_INFO=/user/1
|
165
|
-
# on path("user"), path("(\\d+)") do |uid|
|
166
|
-
#
|
167
|
-
# In fact, the other matchers (#segment, #number, #extension)
|
168
|
-
# ride on this method.
|
169
|
-
def path(pattern)
|
170
|
-
lambda { consume(pattern) }
|
171
|
-
end
|
172
|
-
|
173
|
-
# @private Used by #path to adjust the `PATH_INFO` and `SCRIPT_NAME`.
|
174
|
-
# This is done so that nesting of matchers would work.
|
175
|
-
#
|
176
|
-
# @example
|
177
|
-
# # PATH_INFO=/doctors/account
|
178
|
-
# on path("doctors") do
|
179
|
-
# # PATH_INFO = /account
|
180
|
-
# on path("account") do
|
181
|
-
# res.write "Settings page"
|
182
|
-
# end
|
183
|
-
# end
|
184
145
|
def consume(pattern)
|
185
146
|
return unless match = env["PATH_INFO"].match(/\A\/(#{pattern})(?:\/|\z)/)
|
186
147
|
|
@@ -193,36 +154,26 @@ module Cuba
|
|
193
154
|
end
|
194
155
|
private :consume
|
195
156
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
# A matcher for anything without slashes. Useful for mapping to slugs.
|
207
|
-
#
|
208
|
-
# @example
|
209
|
-
# on path("article"), segment do |slug|
|
210
|
-
# Article.find_by_slug(slug)
|
211
|
-
#
|
212
|
-
# end
|
213
|
-
def segment
|
214
|
-
path("([^\\/]+)")
|
157
|
+
def match(matcher, segment = "([\\.a-zA-Z0-9\\-]+)")
|
158
|
+
case matcher
|
159
|
+
when String then consume(matcher.gsub(/:\w+/, segment))
|
160
|
+
when Regexp then consume(matcher)
|
161
|
+
when Symbol then consume(segment)
|
162
|
+
when Proc then matcher.call
|
163
|
+
else
|
164
|
+
matcher
|
165
|
+
end
|
215
166
|
end
|
216
167
|
|
217
|
-
# A matcher for files with a certain
|
168
|
+
# A matcher for files with a certain extname.
|
218
169
|
#
|
219
170
|
# @example
|
220
171
|
# # PATH_INFO=/style/app.css
|
221
|
-
# on
|
172
|
+
# on "style", extname("css") do |file|
|
222
173
|
# res.write file # writes app
|
223
174
|
# end
|
224
|
-
def
|
225
|
-
|
175
|
+
def extname(ext = "\\w+")
|
176
|
+
lambda { consume("([^\\/]+?)\.#{ext}\\z") }
|
226
177
|
end
|
227
178
|
|
228
179
|
# Used to ensure that certain request parameters are present. Acts like a
|
@@ -230,7 +181,7 @@ module Cuba
|
|
230
181
|
#
|
231
182
|
# @example
|
232
183
|
# # POST with data like user[fname]=John&user[lname]=Doe
|
233
|
-
# on
|
184
|
+
# on "signup", param("user") do |atts|
|
234
185
|
# User.create(atts)
|
235
186
|
# end
|
236
187
|
def param(key, default = nil)
|
@@ -244,11 +195,11 @@ module Cuba
|
|
244
195
|
# Useful for matching against the request host (i.e. HTTP_HOST).
|
245
196
|
#
|
246
197
|
# @example
|
247
|
-
# on host("account1.example.com"),
|
198
|
+
# on host("account1.example.com"), "api" do
|
248
199
|
# res.write "You have reached the API of account1."
|
249
200
|
# end
|
250
201
|
def host(hostname)
|
251
|
-
req.host
|
202
|
+
hostname === req.host
|
252
203
|
end
|
253
204
|
|
254
205
|
# If you want to match against the HTTP_ACCEPT value.
|
@@ -279,10 +230,10 @@ module Cuba
|
|
279
230
|
# Syntatic sugar for providing HTTP Verb matching.
|
280
231
|
#
|
281
232
|
# @example
|
282
|
-
# on get,
|
233
|
+
# on get, "signup" do
|
283
234
|
# end
|
284
235
|
#
|
285
|
-
# on post,
|
236
|
+
# on post, "signup" do
|
286
237
|
# end
|
287
238
|
def get ; req.get? end
|
288
239
|
def post ; req.post? end
|
@@ -297,13 +248,13 @@ module Cuba
|
|
297
248
|
# run Cuba::Ron.new { on(default) { res.redirect(*args) }}
|
298
249
|
# end
|
299
250
|
#
|
300
|
-
# on
|
251
|
+
# on "account" do
|
301
252
|
# redirect "/login" unless session["uid"]
|
302
253
|
#
|
303
254
|
# res.write "Super secure account info."
|
304
255
|
# end
|
305
256
|
def run(app)
|
306
|
-
throw :
|
257
|
+
throw :ron_run_next_app, app
|
307
258
|
end
|
308
259
|
end
|
309
260
|
end
|
data/lib/cuba/version.rb
CHANGED
data/test/captures.rb
CHANGED
@@ -31,7 +31,7 @@ end
|
|
31
31
|
|
32
32
|
test "doesn't yield the path" do
|
33
33
|
Cuba.define do
|
34
|
-
on get,
|
34
|
+
on get, "home" do |*args|
|
35
35
|
res.write args.size
|
36
36
|
end
|
37
37
|
end
|
@@ -46,7 +46,7 @@ end
|
|
46
46
|
|
47
47
|
test "yields the segment" do
|
48
48
|
Cuba.define do
|
49
|
-
on get,
|
49
|
+
on get, "user", :id do |id|
|
50
50
|
res.write id
|
51
51
|
end
|
52
52
|
end
|
@@ -61,7 +61,7 @@ end
|
|
61
61
|
|
62
62
|
test "yields a number" do
|
63
63
|
Cuba.define do
|
64
|
-
on get,
|
64
|
+
on get, "user", :id do |id|
|
65
65
|
res.write id
|
66
66
|
end
|
67
67
|
end
|
@@ -74,9 +74,9 @@ test "yields a number" do
|
|
74
74
|
assert_equal ["101"], resp.body
|
75
75
|
end
|
76
76
|
|
77
|
-
test "yields an
|
77
|
+
test "yields an extname" do
|
78
78
|
Cuba.define do
|
79
|
-
on get,
|
79
|
+
on get, "css", extname("css") do |file|
|
80
80
|
res.write file
|
81
81
|
end
|
82
82
|
end
|
@@ -91,7 +91,7 @@ end
|
|
91
91
|
|
92
92
|
test "yields a param" do
|
93
93
|
Cuba.define do
|
94
|
-
on get,
|
94
|
+
on get, "signup", param("email") do |email|
|
95
95
|
res.write email
|
96
96
|
end
|
97
97
|
end
|
@@ -107,9 +107,9 @@ end
|
|
107
107
|
|
108
108
|
test "yields a segment per nested block" do
|
109
109
|
Cuba.define do
|
110
|
-
on
|
111
|
-
on
|
112
|
-
on
|
110
|
+
on :one do |one|
|
111
|
+
on :two do |two|
|
112
|
+
on :three do |three|
|
113
113
|
res.write one
|
114
114
|
res.write two
|
115
115
|
res.write three
|
@@ -124,4 +124,19 @@ test "yields a segment per nested block" do
|
|
124
124
|
_, _, resp = Cuba.call(env)
|
125
125
|
|
126
126
|
assert_equal ["one", "two", "three"], resp.body
|
127
|
+
end
|
128
|
+
|
129
|
+
test "consumes a slash if needed" do
|
130
|
+
Cuba.define do
|
131
|
+
on get, "(.+\\.css)" do |file|
|
132
|
+
res.write file
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/foo/bar.css",
|
137
|
+
"SCRIPT_NAME" => "/" }
|
138
|
+
|
139
|
+
_, _, resp = Cuba.call(env)
|
140
|
+
|
141
|
+
assert_equal ["foo/bar.css"], resp.body
|
127
142
|
end
|
@@ -2,8 +2,8 @@ require File.expand_path("helper", File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
setup do
|
4
4
|
Cuba.define do
|
5
|
-
on
|
6
|
-
on
|
5
|
+
on "styles" do
|
6
|
+
on extname("css") do |file|
|
7
7
|
res.write file
|
8
8
|
end
|
9
9
|
end
|
@@ -18,4 +18,4 @@ test "/styles/reset.css" do |env|
|
|
18
18
|
_, _, resp = Cuba.call(env)
|
19
19
|
|
20
20
|
assert_equal ["reset"], resp.body
|
21
|
-
end
|
21
|
+
end
|
data/test/host.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
test "matches a host" do
|
4
|
+
Cuba.define do
|
5
|
+
on host("example.com") do
|
6
|
+
res.write "worked"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
env = { "HTTP_HOST" => "example.com" }
|
11
|
+
|
12
|
+
_, _, resp = Cuba.call(env)
|
13
|
+
|
14
|
+
assert_equal ["worked"], resp.body
|
15
|
+
end
|
16
|
+
|
17
|
+
test "matches a host with a regexp" do
|
18
|
+
Cuba.define do
|
19
|
+
on host(/example/) do
|
20
|
+
res.write "worked"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
env = { "HTTP_HOST" => "example.com" }
|
25
|
+
|
26
|
+
_, _, resp = Cuba.call(env)
|
27
|
+
|
28
|
+
assert_equal ["worked"], resp.body
|
29
|
+
end
|
data/test/integration.rb
CHANGED
@@ -29,7 +29,7 @@ test "use passes in the arguments and block" do
|
|
29
29
|
|
30
30
|
Cuba.define do
|
31
31
|
on get do
|
32
|
-
on
|
32
|
+
on "hello" do
|
33
33
|
"Default"
|
34
34
|
end
|
35
35
|
end
|
@@ -52,7 +52,7 @@ test "reset and use" do
|
|
52
52
|
|
53
53
|
Cuba.define do
|
54
54
|
on get do
|
55
|
-
on
|
55
|
+
on "hello" do
|
56
56
|
res.write "Default"
|
57
57
|
end
|
58
58
|
end
|
@@ -66,7 +66,7 @@ test "reset and use" do
|
|
66
66
|
|
67
67
|
Cuba.define do
|
68
68
|
on get do
|
69
|
-
on
|
69
|
+
on "hello" do
|
70
70
|
res.write "2nd Default"
|
71
71
|
end
|
72
72
|
end
|
data/test/match.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
setup do
|
4
|
+
{ "SCRIPT_NAME" => "/", "PATH_INFO" => "/posts/123" }
|
5
|
+
end
|
6
|
+
|
7
|
+
test "text-book example" do |env|
|
8
|
+
Cuba.define do
|
9
|
+
on "posts/:id" do |id|
|
10
|
+
res.write id
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
_, _, resp = Cuba.call(env)
|
15
|
+
|
16
|
+
assert_equal ["123"], resp.body
|
17
|
+
end
|
18
|
+
|
19
|
+
test "multi-param" do |env|
|
20
|
+
Cuba.define do
|
21
|
+
on "u/:uid/posts/:id" do |uid, id|
|
22
|
+
res.write uid
|
23
|
+
res.write id
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
env["PATH_INFO"] = "/u/jdoe/posts/123"
|
28
|
+
|
29
|
+
_, _, resp = Cuba.call(env)
|
30
|
+
|
31
|
+
assert_equal ["jdoe", "123"], resp.body
|
32
|
+
end
|
33
|
+
|
34
|
+
test "regex nesting" do |env|
|
35
|
+
Cuba.define do
|
36
|
+
on /u\/(\w+)/ do |uid|
|
37
|
+
res.write uid
|
38
|
+
|
39
|
+
on /posts\/(\d+)/ do |id|
|
40
|
+
res.write id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
env["PATH_INFO"] = "/u/jdoe/posts/123"
|
46
|
+
|
47
|
+
_, _, resp = Cuba.call(env)
|
48
|
+
|
49
|
+
assert_equal ["jdoe", "123"], resp.body
|
50
|
+
end
|
51
|
+
|
52
|
+
test "regex nesting colon param style" do |env|
|
53
|
+
Cuba.define do
|
54
|
+
on /u:(\w+)/ do |uid|
|
55
|
+
res.write uid
|
56
|
+
|
57
|
+
on /posts:(\d+)/ do |id|
|
58
|
+
res.write id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
env["PATH_INFO"] = "/u:jdoe/posts:123"
|
64
|
+
|
65
|
+
_, _, resp = Cuba.call(env)
|
66
|
+
|
67
|
+
assert_equal ["jdoe", "123"], resp.body
|
68
|
+
end
|
69
|
+
|
70
|
+
test "symbol matching" do |env|
|
71
|
+
Cuba.define do
|
72
|
+
on "user", :id do |uid|
|
73
|
+
res.write uid
|
74
|
+
|
75
|
+
on "posts", :pid do |id|
|
76
|
+
res.write id
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
env["PATH_INFO"] = "/user/jdoe/posts/123"
|
82
|
+
|
83
|
+
_, _, resp = Cuba.call(env)
|
84
|
+
|
85
|
+
assert_equal ["jdoe", "123"], resp.body
|
86
|
+
end
|
data/test/number.rb
CHANGED
@@ -6,8 +6,8 @@ end
|
|
6
6
|
|
7
7
|
test "paths and numbers" do |env|
|
8
8
|
Cuba.define do
|
9
|
-
on
|
10
|
-
on
|
9
|
+
on "about" do
|
10
|
+
on :one, :two do |one, two|
|
11
11
|
res.write one
|
12
12
|
res.write two
|
13
13
|
end
|
@@ -21,8 +21,8 @@ end
|
|
21
21
|
|
22
22
|
test "paths and decimals" do |env|
|
23
23
|
Cuba.define do
|
24
|
-
on
|
25
|
-
on
|
24
|
+
on "about" do
|
25
|
+
on /(\d+)/ do |one|
|
26
26
|
res.write one
|
27
27
|
end
|
28
28
|
end
|
@@ -33,4 +33,4 @@ test "paths and decimals" do |env|
|
|
33
33
|
_, _, resp = Cuba.call(env)
|
34
34
|
|
35
35
|
assert_equal [], resp.body
|
36
|
-
end
|
36
|
+
end
|
data/test/on.rb
CHANGED
@@ -12,6 +12,18 @@ test "executes on true" do
|
|
12
12
|
assert_equal ["+1"], resp.body
|
13
13
|
end
|
14
14
|
|
15
|
+
test "executes on non-false" do
|
16
|
+
Cuba.define do
|
17
|
+
on "123" do
|
18
|
+
res.write "+1"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
_, _, resp = Cuba.call({ "PATH_INFO" => "/123", "SCRIPT_NAME" => "/" })
|
23
|
+
|
24
|
+
assert_equal ["+1"], resp.body
|
25
|
+
end
|
26
|
+
|
15
27
|
test "restores SCRIPT_NAME and PATH_INFO" do
|
16
28
|
Cuba.define do
|
17
29
|
on true do
|
data/test/path.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
|
7
7
|
test "one level path" do |env|
|
8
8
|
Cuba.define do
|
9
|
-
on
|
9
|
+
on "about" do
|
10
10
|
res.write "About"
|
11
11
|
end
|
12
12
|
end
|
@@ -19,12 +19,12 @@ end
|
|
19
19
|
|
20
20
|
test "two level nested paths" do |env|
|
21
21
|
Cuba.define do
|
22
|
-
on
|
23
|
-
on
|
22
|
+
on "about" do
|
23
|
+
on "1" do
|
24
24
|
res.write "+1"
|
25
25
|
end
|
26
26
|
|
27
|
-
on
|
27
|
+
on "2" do
|
28
28
|
res.write "+2"
|
29
29
|
end
|
30
30
|
end
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
test "two level inlined paths" do |env|
|
47
47
|
Cuba.define do
|
48
|
-
on
|
48
|
+
on "a/b" do
|
49
49
|
res.write "a"
|
50
50
|
res.write "b"
|
51
51
|
end
|
@@ -60,7 +60,7 @@ end
|
|
60
60
|
|
61
61
|
test "a path with some regex captures" do |env|
|
62
62
|
Cuba.define do
|
63
|
-
on
|
63
|
+
on "user(\\d+)" do |uid|
|
64
64
|
res.write uid
|
65
65
|
end
|
66
66
|
end
|
@@ -71,3 +71,17 @@ test "a path with some regex captures" do |env|
|
|
71
71
|
|
72
72
|
assert_equal ["123"], resp.body
|
73
73
|
end
|
74
|
+
|
75
|
+
test "matching the root" do |env|
|
76
|
+
Cuba.define do
|
77
|
+
on "" do
|
78
|
+
res.write "Home"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
env["PATH_INFO"] = "/"
|
83
|
+
|
84
|
+
_, _, resp = Cuba.call(env)
|
85
|
+
|
86
|
+
assert_equal ["Home"], resp.body
|
87
|
+
end
|
data/test/run.rb
CHANGED
@@ -6,7 +6,7 @@ test "redirect canonical example" do
|
|
6
6
|
run Cuba::Ron.new { on(true) { res.redirect(*args) }}
|
7
7
|
end
|
8
8
|
|
9
|
-
on
|
9
|
+
on "account" do
|
10
10
|
redirect "/login", 307
|
11
11
|
|
12
12
|
res.write "Super secure content"
|
@@ -20,4 +20,4 @@ test "redirect canonical example" do
|
|
20
20
|
assert_equal "/login", resp["Location"]
|
21
21
|
assert_equal 307, resp.status
|
22
22
|
assert_equal [], resp.body
|
23
|
-
end
|
23
|
+
end
|
data/test/segment.rb
CHANGED
@@ -2,8 +2,8 @@ require File.expand_path("helper", File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
setup do
|
4
4
|
Cuba.define do
|
5
|
-
on
|
6
|
-
on
|
5
|
+
on "post" do
|
6
|
+
on :id do |id|
|
7
7
|
res.write id
|
8
8
|
end
|
9
9
|
end
|
@@ -42,4 +42,4 @@ test "matches only the first segment available" do |env|
|
|
42
42
|
_, _, resp = Cuba.call(env)
|
43
43
|
|
44
44
|
assert_equal ["one"], resp.body
|
45
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version:
|
4
|
+
prerelease: 6
|
5
|
+
version: 2.0.0.rc1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michel Martens
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-25 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: "1.
|
35
|
+
version: "1.2"
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: "0
|
46
|
+
version: "1.0"
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: "0.
|
57
|
+
version: "0.4"
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
60
|
description: Cuba is a light wrapper for Rum, a microframework for Rack applications.
|
@@ -77,9 +77,11 @@ files:
|
|
77
77
|
- cuba.gemspec
|
78
78
|
- test/accept.rb
|
79
79
|
- test/captures.rb
|
80
|
-
- test/
|
80
|
+
- test/extname.rb
|
81
81
|
- test/helper.rb
|
82
|
+
- test/host.rb
|
82
83
|
- test/integration.rb
|
84
|
+
- test/match.rb
|
83
85
|
- test/number.rb
|
84
86
|
- test/on.rb
|
85
87
|
- test/path.rb
|
@@ -103,9 +105,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
none: false
|
105
107
|
requirements:
|
106
|
-
- - "
|
108
|
+
- - ">"
|
107
109
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
110
|
+
version: 1.3.1
|
109
111
|
requirements: []
|
110
112
|
|
111
113
|
rubyforge_project:
|