cuba 2.2.1 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.markdown +116 -102
- data/cuba.gemspec +2 -3
- data/lib/cuba.rb +35 -48
- data/lib/cuba/settings.rb +25 -0
- data/test/accept.rb +0 -2
- data/test/helper.rb +7 -0
- data/test/match.rb +5 -5
- data/test/middleware.rb +10 -8
- data/test/number.rb +2 -2
- data/test/plugin.rb +68 -0
- data/test/session.rb +21 -0
- data/test/settings.rb +39 -0
- metadata +19 -18
- data/lib/cuba/version.rb +0 -3
- data/test/layout.rb +0 -15
data/CHANGELOG
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
3.0.0.rc1
|
2
|
+
|
3
|
+
* Remove Cuba.build. Use subclassing instead.
|
4
|
+
* Remove warnings.
|
5
|
+
* Remove redefinition of Rack::Response#redirect.
|
6
|
+
* Integrate Cuba.plugin and Cuba.settings.
|
7
|
+
* Remove Cuba::VERSION.
|
8
|
+
* Rename _call to call! (inspired from Sinatra).
|
9
|
+
* Fix a memory leak with the caching used in Tilt.
|
10
|
+
* Adding syntax highlighting to the README Code blocks
|
data/README.markdown
CHANGED
@@ -30,40 +30,43 @@ Usage
|
|
30
30
|
|
31
31
|
Here's a simple application:
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
``` ruby
|
34
|
+
# cat hello_world.rb
|
35
|
+
require "cuba"
|
35
36
|
|
36
|
-
|
37
|
+
Cuba.use Rack::Session::Cookie
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
on true do
|
45
|
-
res.redirect "/hello"
|
46
|
-
end
|
47
|
-
end
|
39
|
+
Cuba.define do
|
40
|
+
on get do
|
41
|
+
on "hello" do
|
42
|
+
res.write "Hello world!"
|
48
43
|
end
|
49
44
|
|
50
|
-
|
51
|
-
|
45
|
+
on true do
|
46
|
+
res.redirect "/hello"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
visit "/"
|
51
|
+
# cat hello_world_test.rb
|
52
|
+
require "cuba/test"
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
scope do
|
55
|
+
test "Homepage" do
|
56
|
+
visit "/"
|
57
|
+
assert has_content?("Hello world!")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
60
61
|
|
61
62
|
To run it, you can create a `config.ru` file:
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
``` ruby
|
65
|
+
# cat config.ru
|
66
|
+
require "./hello_world"
|
65
67
|
|
66
|
-
|
68
|
+
run Cuba
|
69
|
+
```
|
67
70
|
|
68
71
|
You can now run `rackup` and enjoy what you have just created.
|
69
72
|
|
@@ -72,77 +75,80 @@ Matchers
|
|
72
75
|
|
73
76
|
Here's an example showcasing how different matchers work:
|
74
77
|
|
75
|
-
|
78
|
+
``` ruby
|
79
|
+
require "cuba"
|
76
80
|
|
77
|
-
|
81
|
+
Cuba.use Rack::Session::Cookie
|
78
82
|
|
79
|
-
|
83
|
+
Cuba.define do
|
80
84
|
|
81
|
-
|
82
|
-
|
85
|
+
# only GET requests
|
86
|
+
on get do
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
# /
|
89
|
+
on "" do
|
90
|
+
res.write "Home"
|
91
|
+
end
|
88
92
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
# /about
|
94
|
+
on "about" do
|
95
|
+
res.write "About"
|
96
|
+
end
|
97
|
+
|
98
|
+
# /styles/basic.css
|
99
|
+
on "styles", extension("css") do |file|
|
100
|
+
res.write "Filename: #{file}" #=> "Filename: basic"
|
101
|
+
end
|
102
|
+
|
103
|
+
# /post/2011/02/16/hello
|
104
|
+
on "post/:y/:m/:d/:slug" do |y, m, d, slug|
|
105
|
+
res.write "#{y}-#{m}-#{d} #{slug}" #=> "2011-02-16 hello"
|
106
|
+
end
|
93
107
|
|
94
|
-
|
95
|
-
|
96
|
-
res.write "Filename: #{file}" #=> "Filename: basic"
|
97
|
-
end
|
108
|
+
# /username/foobar
|
109
|
+
on "username/:username" do |username|
|
98
110
|
|
99
|
-
|
100
|
-
on "post/:y/:m/:d/:slug" do |y, m, d, slug|
|
101
|
-
res.write "#{y}-#{m}-#{d} #{slug}" #=> "2011-02-16 hello"
|
102
|
-
end
|
111
|
+
user = User.find_by_username(username) # username == "foobar"
|
103
112
|
|
104
|
-
|
105
|
-
|
113
|
+
# /username/foobar/posts
|
114
|
+
on "posts" do
|
106
115
|
|
107
|
-
|
116
|
+
# You can access `user` here, because the `on` blocks
|
117
|
+
# are closures.
|
118
|
+
res.write "Total Posts: #{user.posts.size}" #=> "Total Posts: 6"
|
119
|
+
end
|
108
120
|
|
109
|
-
|
110
|
-
|
121
|
+
# /username/foobar/following
|
122
|
+
on "following" do
|
123
|
+
res.write user.following.size #=> "1301"
|
124
|
+
end
|
125
|
+
end
|
111
126
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
127
|
+
# /search?q=barbaz
|
128
|
+
on "search", param("q") do |query|
|
129
|
+
res.write "Searched for #{query}" #=> "Searched for barbaz"
|
130
|
+
end
|
131
|
+
end
|
116
132
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
133
|
+
# only POST requests
|
134
|
+
on post do
|
135
|
+
on "login"
|
122
136
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
137
|
+
# POST /login, user: foo, pass: baz
|
138
|
+
on param("user"), param("pass") do |user, pass|
|
139
|
+
res.write "#{user}:#{pass}" #=> "foo:baz"
|
127
140
|
end
|
128
141
|
|
129
|
-
#
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
# POST /login, user: foo, pass: baz
|
134
|
-
on param("user"), param("pass") do |user, pass|
|
135
|
-
res.write "#{user}:#{pass}" #=> "foo:baz"
|
136
|
-
end
|
137
|
-
|
138
|
-
# If the params `user` and `pass` are not provided, this block will
|
139
|
-
# get executed.
|
140
|
-
on true do
|
141
|
-
res.write "You need to provide user and pass!"
|
142
|
-
end
|
143
|
-
end
|
142
|
+
# If the params `user` and `pass` are not provided, this block will
|
143
|
+
# get executed.
|
144
|
+
on true do
|
145
|
+
res.write "You need to provide user and pass!"
|
144
146
|
end
|
145
147
|
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
146
152
|
|
147
153
|
HTTP Verbs
|
148
154
|
----------
|
@@ -156,11 +162,13 @@ and inspect the environment via the `env` object, and check for example if
|
|
156
162
|
|
157
163
|
What follows is an example of different ways of saying the same thing:
|
158
164
|
|
159
|
-
|
165
|
+
``` ruby
|
166
|
+
on env["REQUEST_METHOD"] == "GET", "api" do ... end
|
160
167
|
|
161
|
-
|
168
|
+
on req.get?, "api" do ... end
|
162
169
|
|
163
|
-
|
170
|
+
on get, "api" do ... end
|
171
|
+
```
|
164
172
|
|
165
173
|
Actually, `get` is syntax sugar for `req.get?`, which in turn is syntax sugar
|
166
174
|
for `env["REQUEST_METHOD"] == "GET"`.
|
@@ -198,21 +206,23 @@ Composition
|
|
198
206
|
|
199
207
|
You can mount a Cuba app, along with middlewares, inside another Cuba app:
|
200
208
|
|
201
|
-
|
209
|
+
``` ruby
|
210
|
+
class API < Cuba; end
|
202
211
|
|
203
|
-
|
212
|
+
API.use SomeMiddleware
|
204
213
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
214
|
+
API.define do
|
215
|
+
on param("url") do |url|
|
216
|
+
...
|
217
|
+
end
|
218
|
+
end
|
210
219
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
220
|
+
Cuba.define do
|
221
|
+
on "api" do
|
222
|
+
run API
|
223
|
+
end
|
224
|
+
end
|
225
|
+
```
|
216
226
|
|
217
227
|
Testing
|
218
228
|
-------
|
@@ -222,16 +232,18 @@ Given that Cuba is essentially Rack, it is very easy to test with `Webrat` or
|
|
222
232
|
and [Capybara][capybara], and if you want to use the same for your tests it is
|
223
233
|
as easy as requiring `cuba/test`:
|
224
234
|
|
225
|
-
|
226
|
-
|
235
|
+
``` ruby
|
236
|
+
require "cuba/test"
|
237
|
+
require "your/app"
|
227
238
|
|
228
|
-
|
229
|
-
|
230
|
-
|
239
|
+
scope do
|
240
|
+
test "Homepage" do
|
241
|
+
visit "/"
|
231
242
|
|
232
|
-
|
233
|
-
|
234
|
-
|
243
|
+
assert has_content?("Hello world!")
|
244
|
+
end
|
245
|
+
end
|
246
|
+
```
|
235
247
|
|
236
248
|
To read more about testing, check the documentation for [Cutest][cutest] and
|
237
249
|
[Capybara][capybara].
|
@@ -239,4 +251,6 @@ To read more about testing, check the documentation for [Cutest][cutest] and
|
|
239
251
|
Installation
|
240
252
|
------------
|
241
253
|
|
242
|
-
|
254
|
+
``` ruby
|
255
|
+
$ gem install cuba
|
256
|
+
```
|
data/cuba.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require "./lib/cuba/version"
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
2
|
s.name = "cuba"
|
5
|
-
s.version =
|
3
|
+
s.version = "3.0.0.rc1"
|
6
4
|
s.summary = "Microframework for web applications."
|
7
5
|
s.description = "Cuba is a microframework for web applications."
|
8
6
|
s.authors = ["Michel Martens"]
|
@@ -11,6 +9,7 @@ Gem::Specification.new do |s|
|
|
11
9
|
|
12
10
|
s.files = Dir[
|
13
11
|
"LICENSE",
|
12
|
+
"CHANGELOG",
|
14
13
|
"README.markdown",
|
15
14
|
"Rakefile",
|
16
15
|
"lib/**/*.rb",
|
data/lib/cuba.rb
CHANGED
@@ -1,17 +1,4 @@
|
|
1
1
|
require "rack"
|
2
|
-
require "tilt"
|
3
|
-
require "cuba/version"
|
4
|
-
|
5
|
-
class Rack::Response
|
6
|
-
# 301 Moved Permanently
|
7
|
-
# 302 Found
|
8
|
-
# 303 See Other
|
9
|
-
# 307 Temporary Redirect
|
10
|
-
def redirect(target, status = 302)
|
11
|
-
self.status = status
|
12
|
-
self["Location"] = target
|
13
|
-
end
|
14
|
-
end
|
15
2
|
|
16
3
|
class Cuba
|
17
4
|
class RedefinitionError < StandardError
|
@@ -19,6 +6,10 @@ class Cuba
|
|
19
6
|
|
20
7
|
@@methods = []
|
21
8
|
|
9
|
+
class << self
|
10
|
+
undef method_added
|
11
|
+
end
|
12
|
+
|
22
13
|
def self.method_added(meth)
|
23
14
|
@@methods << meth
|
24
15
|
end
|
@@ -40,10 +31,6 @@ class Cuba
|
|
40
31
|
app.run new(&block)
|
41
32
|
end
|
42
33
|
|
43
|
-
def self.build
|
44
|
-
Class.new(self)
|
45
|
-
end
|
46
|
-
|
47
34
|
def self.prototype
|
48
35
|
@prototype ||= app.to_app
|
49
36
|
end
|
@@ -52,6 +39,21 @@ class Cuba
|
|
52
39
|
prototype.call(env)
|
53
40
|
end
|
54
41
|
|
42
|
+
def self.plugin(mixin)
|
43
|
+
include mixin
|
44
|
+
extend mixin::ClassMethods if defined?(mixin::ClassMethods)
|
45
|
+
|
46
|
+
mixin.setup(self) if mixin.respond_to?(:setup)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.settings
|
50
|
+
@settings ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.inherited(child)
|
54
|
+
child.settings.replace(settings)
|
55
|
+
end
|
56
|
+
|
55
57
|
attr :env
|
56
58
|
attr :req
|
57
59
|
attr :res
|
@@ -62,11 +64,15 @@ class Cuba
|
|
62
64
|
@captures = []
|
63
65
|
end
|
64
66
|
|
67
|
+
def settings
|
68
|
+
self.class.settings
|
69
|
+
end
|
70
|
+
|
65
71
|
def call(env)
|
66
|
-
dup.
|
72
|
+
dup.call!(env)
|
67
73
|
end
|
68
74
|
|
69
|
-
def
|
75
|
+
def call!(env)
|
70
76
|
@env = env
|
71
77
|
@req = Rack::Request.new(env)
|
72
78
|
@res = Rack::Response.new
|
@@ -86,33 +92,10 @@ class Cuba
|
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
private :_cache
|
95
|
-
|
96
|
-
# Render any type of template file supported by Tilt.
|
97
|
-
#
|
98
|
-
# @example
|
99
|
-
#
|
100
|
-
# # Renders home, and is assumed to be HAML.
|
101
|
-
# render("home.haml")
|
102
|
-
#
|
103
|
-
# # Renders with some local variables
|
104
|
-
# render("home.haml", site_name: "My Site")
|
105
|
-
#
|
106
|
-
# # Renders with HAML options
|
107
|
-
# render("home.haml", {}, ugly: true, format: :html5)
|
108
|
-
#
|
109
|
-
# # Renders in layout
|
110
|
-
# render("layout.haml") { render("home.haml") }
|
111
|
-
#
|
112
|
-
def render(template, locals = {}, options = {}, &block)
|
113
|
-
_cache.fetch(template, locals) {
|
114
|
-
Tilt.new(template, 1, options)
|
115
|
-
}.render(self, locals, &block)
|
95
|
+
def session
|
96
|
+
env["rack.session"] || raise(RuntimeError,
|
97
|
+
"You're missing a session handler. You can get started " +
|
98
|
+
"by adding Cuba.use Rack::Session::Cookie")
|
116
99
|
end
|
117
100
|
|
118
101
|
# The heart of the path / verb / any condition matching.
|
@@ -155,7 +138,7 @@ class Cuba
|
|
155
138
|
# The captures we yield here were generated and assembled
|
156
139
|
# by evaluating each of the `arg`s above. Most of these
|
157
140
|
# are carried out by #consume.
|
158
|
-
yield
|
141
|
+
yield(*captures)
|
159
142
|
|
160
143
|
halt res.finish
|
161
144
|
end
|
@@ -169,7 +152,7 @@ class Cuba
|
|
169
152
|
yield
|
170
153
|
|
171
154
|
ensure
|
172
|
-
env["SCRIPT_NAME"], env["PATH_INFO"] = script, path
|
155
|
+
env["SCRIPT_NAME"], env["PATH_INFO"] = script, path
|
173
156
|
end
|
174
157
|
private :try
|
175
158
|
|
@@ -292,6 +275,10 @@ class Cuba
|
|
292
275
|
throw :halt, response
|
293
276
|
end
|
294
277
|
|
278
|
+
class << self
|
279
|
+
undef method_added
|
280
|
+
end
|
281
|
+
|
295
282
|
# In order to prevent people from overriding the standard Cuba
|
296
283
|
# methods like `get`, `put`, etc, we add this as a safety measure.
|
297
284
|
def self.method_added(meth)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Cuba
|
2
|
+
module Settings
|
3
|
+
def settings
|
4
|
+
self.class
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def set(key, value)
|
9
|
+
metaclass.send :attr_writer, key
|
10
|
+
metaclass.module_eval %{
|
11
|
+
def #{key}
|
12
|
+
@#{key} ||= #{value.inspect}
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
send :"#{key}=", value
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def metaclass
|
21
|
+
class << self; self; end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/accept.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/match.rb
CHANGED
@@ -33,10 +33,10 @@ end
|
|
33
33
|
|
34
34
|
test "regex nesting" do |env|
|
35
35
|
Cuba.define do
|
36
|
-
on
|
36
|
+
on(/u\/(\w+)/) do |uid|
|
37
37
|
res.write uid
|
38
38
|
|
39
|
-
on
|
39
|
+
on(/posts\/(\d+)/) do |id|
|
40
40
|
res.write id
|
41
41
|
end
|
42
42
|
end
|
@@ -51,10 +51,10 @@ end
|
|
51
51
|
|
52
52
|
test "regex nesting colon param style" do |env|
|
53
53
|
Cuba.define do
|
54
|
-
on
|
54
|
+
on(/u:(\w+)/) do |uid|
|
55
55
|
res.write uid
|
56
56
|
|
57
|
-
on
|
57
|
+
on(/posts:(\d+)/) do |id|
|
58
58
|
res.write id
|
59
59
|
end
|
60
60
|
end
|
@@ -83,4 +83,4 @@ test "symbol matching" do |env|
|
|
83
83
|
_, _, resp = Cuba.call(env)
|
84
84
|
|
85
85
|
assert_equal ["jdoe", "123"], resp.body
|
86
|
-
end
|
86
|
+
end
|
data/test/middleware.rb
CHANGED
@@ -13,13 +13,15 @@ class Shrimp
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test do
|
16
|
-
API
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
class API < Cuba
|
17
|
+
use Shrimp
|
18
|
+
|
19
|
+
define do
|
20
|
+
on "v1/test" do
|
21
|
+
res.write "OK"
|
22
|
+
res.write "1"
|
23
|
+
res.write "2"
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -38,4 +40,4 @@ test do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
assert_equal ["2", "1", "OK"], arr
|
41
|
-
end
|
43
|
+
end
|
data/test/number.rb
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
test "paths and decimals" do |env|
|
23
23
|
Cuba.define do
|
24
24
|
on "about" do
|
25
|
-
on
|
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/plugin.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
scope do
|
4
|
+
module Helper
|
5
|
+
def clean(str)
|
6
|
+
str.strip
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test do
|
11
|
+
Cuba.plugin Helper
|
12
|
+
|
13
|
+
Cuba.define do
|
14
|
+
on default do
|
15
|
+
res.write clean " foo "
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
_, _, body = Cuba.call({})
|
20
|
+
|
21
|
+
assert_response body, ["foo"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
scope do
|
26
|
+
module Number
|
27
|
+
def num
|
28
|
+
1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Plugin
|
33
|
+
def self.setup(app)
|
34
|
+
app.plugin Number
|
35
|
+
end
|
36
|
+
|
37
|
+
def bar
|
38
|
+
"baz"
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
def foo
|
43
|
+
"bar"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
setup do
|
49
|
+
Cuba.plugin Plugin
|
50
|
+
|
51
|
+
Cuba.define do
|
52
|
+
on default do
|
53
|
+
res.write bar
|
54
|
+
res.write num
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test do
|
60
|
+
assert_equal "bar", Cuba.foo
|
61
|
+
end
|
62
|
+
|
63
|
+
test do
|
64
|
+
_, _, body = Cuba.call({})
|
65
|
+
|
66
|
+
assert_response body, ["baz", "1"]
|
67
|
+
end
|
68
|
+
end
|
data/test/session.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
test do
|
4
|
+
Cuba.define do
|
5
|
+
on default do
|
6
|
+
begin
|
7
|
+
session
|
8
|
+
rescue Exception => e
|
9
|
+
res.write e.message
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
_, _, body = Cuba.call({})
|
15
|
+
|
16
|
+
body.each do |e|
|
17
|
+
assert e =~ /Cuba.use Rack::Session::Cookie/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/test/settings.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
test "settings is an empty hash by default" do
|
4
|
+
assert Cuba.settings.kind_of?(Hash)
|
5
|
+
assert Cuba.settings.empty?
|
6
|
+
end
|
7
|
+
|
8
|
+
test "is inheritable and allows overriding" do
|
9
|
+
Cuba.settings[:foo] = "bar"
|
10
|
+
|
11
|
+
class Admin < Cuba; end
|
12
|
+
|
13
|
+
assert_equal "bar", Admin.settings[:foo]
|
14
|
+
|
15
|
+
Admin.settings[:foo] = "baz"
|
16
|
+
|
17
|
+
assert_equal "bar", Cuba.settings[:foo]
|
18
|
+
assert_equal "baz", Admin.settings[:foo]
|
19
|
+
end
|
20
|
+
|
21
|
+
test do
|
22
|
+
Cuba.settings[:hello] = "Hello World"
|
23
|
+
|
24
|
+
Cuba.define do
|
25
|
+
on default do
|
26
|
+
res.write settings[:hello]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
_, _, resp = Cuba.call({ "PATH_INFO" => "/", "SCRIPT_NAME" => ""})
|
31
|
+
|
32
|
+
body = []
|
33
|
+
|
34
|
+
resp.each do |line|
|
35
|
+
body << line
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal ["Hello World"], body
|
39
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michel Martens
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-02-15 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rack
|
17
|
-
requirement: &
|
16
|
+
requirement: &2160204820 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160204820
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: tilt
|
28
|
-
requirement: &
|
27
|
+
requirement: &2160203660 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160203660
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: cutest
|
39
|
-
requirement: &
|
38
|
+
requirement: &2160218800 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ! '>='
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: '0'
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160218800
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: capybara
|
50
|
-
requirement: &
|
49
|
+
requirement: &2160218280 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ! '>='
|
@@ -55,7 +54,7 @@ dependencies:
|
|
55
54
|
version: '0'
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *2160218280
|
59
58
|
description: Cuba is a microframework for web applications.
|
60
59
|
email:
|
61
60
|
- michel@soveran.com
|
@@ -64,10 +63,11 @@ extensions: []
|
|
64
63
|
extra_rdoc_files: []
|
65
64
|
files:
|
66
65
|
- LICENSE
|
66
|
+
- CHANGELOG
|
67
67
|
- README.markdown
|
68
68
|
- Rakefile
|
69
|
+
- lib/cuba/settings.rb
|
69
70
|
- lib/cuba/test.rb
|
70
|
-
- lib/cuba/version.rb
|
71
71
|
- lib/cuba.rb
|
72
72
|
- cuba.gemspec
|
73
73
|
- test/accept.rb
|
@@ -77,18 +77,19 @@ files:
|
|
77
77
|
- test/helper.rb
|
78
78
|
- test/host.rb
|
79
79
|
- test/integration.rb
|
80
|
-
- test/layout.rb
|
81
80
|
- test/match.rb
|
82
81
|
- test/middleware.rb
|
83
82
|
- test/number.rb
|
84
83
|
- test/on.rb
|
85
84
|
- test/param.rb
|
86
85
|
- test/path.rb
|
86
|
+
- test/plugin.rb
|
87
87
|
- test/redefinition.rb
|
88
88
|
- test/root.rb
|
89
89
|
- test/run.rb
|
90
90
|
- test/segment.rb
|
91
|
-
|
91
|
+
- test/session.rb
|
92
|
+
- test/settings.rb
|
92
93
|
homepage: http://github.com/soveran/cuba
|
93
94
|
licenses: []
|
94
95
|
post_install_message:
|
@@ -104,12 +105,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
106
|
none: false
|
106
107
|
requirements:
|
107
|
-
- - ! '
|
108
|
+
- - ! '>'
|
108
109
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
+
version: 1.3.1
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.10
|
113
114
|
signing_key:
|
114
115
|
specification_version: 3
|
115
116
|
summary: Microframework for web applications.
|
data/lib/cuba/version.rb
DELETED
data/test/layout.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
test "simple layout support" do
|
4
|
-
Cuba.define do
|
5
|
-
on true do
|
6
|
-
res.write render("test/fixtures/layout.erb") {
|
7
|
-
render("test/fixtures/content.erb")
|
8
|
-
}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
_, _, resp = Cuba.call({})
|
13
|
-
|
14
|
-
assert_equal ["alfa beta\n\n"], resp.body
|
15
|
-
end
|