cuba 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gems +4 -0
- data/.gitignore +2 -0
- data/CHANGELOG +4 -0
- data/README.md +104 -124
- data/cuba.gemspec +4 -11
- data/examples/config.ru +18 -0
- data/examples/measure.rb +17 -0
- data/examples/rack-response.ru +21 -0
- data/examples/views/home.mote +7 -0
- data/examples/views/layout.mote +11 -0
- data/lib/cuba.rb +11 -2
- data/lib/cuba/render.rb +19 -17
- data/makefile +4 -0
- data/test/integration.rb +1 -1
- data/test/on.rb +60 -0
- data/test/render.rb +10 -16
- data/test/views/about.erb +1 -0
- data/test/views/about.str +1 -0
- data/test/views/content-yield.erb +1 -0
- data/test/views/custom/abs_path.mote +1 -0
- data/test/views/frag.mote +1 -0
- data/test/views/home.erb +2 -0
- data/test/views/home.mote +1 -0
- data/test/views/home.str +2 -0
- data/test/views/layout-alternative.erb +2 -0
- data/test/views/layout-yield.erb +3 -0
- data/test/views/layout.erb +2 -0
- data/test/views/layout.mote +2 -0
- data/test/views/layout.str +2 -0
- data/test/views/test.erb +1 -0
- metadata +30 -8
- data/Rakefile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fc1228862c8a441f9246f55475c5794761605b8
|
4
|
+
data.tar.gz: e5ddde6ab8c8e56c15910551eca0e49960b29c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb9986361bbdbee4d60ed75167870d37bbd16b38aa676a73cc3c5e0f0831c3c4654464f192d015cfd1a0b796858e4389087206e4fb72fa81ef57c1d79f630e8
|
7
|
+
data.tar.gz: f7e6ab58e6517f5768e2773bafcc4a2d8f0d01462be4c443079085b3142813c21eaaebf65cad9c096eb2513e60ca091cc041d3f00c9697aea85ec05879265dc1
|
data/.gems
ADDED
data/.gitignore
ADDED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,16 @@ It integrates many templates via [Tilt][tilt], and testing via
|
|
30
30
|
[capybara]: http://github.com/jnicklas/capybara
|
31
31
|
[rack-test]: https://github.com/brynary/rack-test
|
32
32
|
|
33
|
+
Guide
|
34
|
+
-----
|
35
|
+
|
36
|
+
There's a book called [The Guide to Cuba][guide] that explains how
|
37
|
+
to build web applications by following a minimalistic approach. It
|
38
|
+
is recommended reading for anyone trying to learn the basics of
|
39
|
+
Cuba and other related tools.
|
40
|
+
|
41
|
+
[guide]: http://theguidetocuba.io
|
42
|
+
|
33
43
|
Installation
|
34
44
|
------------
|
35
45
|
|
@@ -162,8 +172,8 @@ Cuba.define do
|
|
162
172
|
res.write "#{user}:#{pass}" #=> "foo:baz"
|
163
173
|
end
|
164
174
|
|
165
|
-
# If the params `user` and `pass` are not provided, this
|
166
|
-
# get executed.
|
175
|
+
# If the params `user` and `pass` are not provided, this
|
176
|
+
# block will get executed.
|
167
177
|
on true do
|
168
178
|
res.write "You need to provide user and pass!"
|
169
179
|
end
|
@@ -175,50 +185,10 @@ end
|
|
175
185
|
Status codes
|
176
186
|
------------
|
177
187
|
|
178
|
-
|
179
|
-
|
180
|
-
is returned if no `on` block succeeds inside a Cuba app.
|
181
|
-
|
182
|
-
As this behavior can be tricky, let's look at some examples:
|
183
|
-
|
184
|
-
``` ruby
|
185
|
-
Cuba.define do
|
186
|
-
on get do
|
187
|
-
on "hello" do
|
188
|
-
res.write "hello world"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# Requests:
|
194
|
-
#
|
195
|
-
# GET / # 200, ""
|
196
|
-
# GET /hello # 200, "hello world"
|
197
|
-
# GET /hello/world # 200, "hello world"
|
198
|
-
```
|
199
|
-
|
200
|
-
As you can see, as soon as `on get` matched, the status code was
|
201
|
-
changed to 200. If you expected some of those requests to return a
|
202
|
-
404 status code, you may be surprised by this behavior.
|
203
|
-
|
204
|
-
In the following example, as both arguments to `on` must match,
|
205
|
-
the requests to `/` return 404.
|
206
|
-
|
207
|
-
``` ruby
|
208
|
-
Cuba.define do
|
209
|
-
on get, "hello" do
|
210
|
-
res.write "hello world"
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# Requests:
|
215
|
-
#
|
216
|
-
# GET / # 404, ""
|
217
|
-
# GET /hello # 200, "hello world"
|
218
|
-
# GET /hello/world # 200, "hello world"
|
219
|
-
```
|
188
|
+
If you don't assign a status code and you don't write to the `res`
|
189
|
+
object, the status will be set as `404`.
|
220
190
|
|
221
|
-
|
191
|
+
For example:
|
222
192
|
|
223
193
|
``` ruby
|
224
194
|
Cuba.define do
|
@@ -226,79 +196,46 @@ Cuba.define do
|
|
226
196
|
on "hello" do
|
227
197
|
res.write "hello world"
|
228
198
|
end
|
229
|
-
|
230
|
-
on default do
|
231
|
-
res.status = 404
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
# Requests:
|
237
|
-
#
|
238
|
-
# GET / # 404, ""
|
239
|
-
# GET /hello # 200, "hello world"
|
240
|
-
# GET /hello/world # 200, "hello world"
|
241
|
-
```
|
242
|
-
|
243
|
-
Yet another way is to mount an application with routes that don't
|
244
|
-
match the request:
|
245
|
-
|
246
|
-
``` ruby
|
247
|
-
SomeApp = Cuba.new do
|
248
|
-
on "bye" do
|
249
|
-
res.write "bye!"
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
Cuba.define do
|
254
|
-
on get do
|
255
|
-
run SomeApp
|
256
199
|
end
|
257
200
|
end
|
258
201
|
|
259
202
|
# Requests:
|
260
203
|
#
|
261
|
-
# GET / # 404
|
262
|
-
# GET /hello #
|
263
|
-
# GET /hello/world #
|
204
|
+
# GET / # 404
|
205
|
+
# GET /hello # 200
|
206
|
+
# GET /hello/world # 200
|
264
207
|
```
|
265
208
|
|
266
|
-
As
|
267
|
-
|
209
|
+
As you can see, as soon as something was written to the response,
|
210
|
+
the status code was changed to 200.
|
268
211
|
|
269
|
-
|
270
|
-
|
271
|
-
following example:
|
212
|
+
If you want to match just "hello", but not "hello/world", you can do
|
213
|
+
as follows:
|
272
214
|
|
273
215
|
``` ruby
|
274
216
|
Cuba.define do
|
275
|
-
res.status = 404
|
276
|
-
|
277
217
|
on get do
|
278
218
|
on "hello" do
|
279
|
-
|
280
|
-
|
219
|
+
on root do
|
220
|
+
res.write "hello world"
|
221
|
+
end
|
281
222
|
end
|
282
223
|
end
|
283
224
|
end
|
284
225
|
|
285
226
|
# Requests:
|
286
227
|
#
|
287
|
-
# GET / # 404
|
288
|
-
# GET /hello # 200
|
289
|
-
# GET /hello/world #
|
228
|
+
# GET / # 404
|
229
|
+
# GET /hello # 200
|
230
|
+
# GET /hello/world # 404
|
290
231
|
```
|
291
232
|
|
292
|
-
|
293
|
-
can match the end of line:
|
233
|
+
You can also use a regular expression to match the end of line:
|
294
234
|
|
295
235
|
``` ruby
|
296
236
|
Cuba.define do
|
297
|
-
res.status = 404
|
298
|
-
|
299
237
|
on get do
|
300
238
|
on /hello\/?\z/ do
|
301
|
-
res.status = 200
|
302
239
|
res.write "hello world"
|
303
240
|
end
|
304
241
|
end
|
@@ -306,9 +243,9 @@ end
|
|
306
243
|
|
307
244
|
# Requests:
|
308
245
|
#
|
309
|
-
# GET / # 404
|
310
|
-
# GET /hello # 200
|
311
|
-
# GET /hello/world # 404
|
246
|
+
# GET / # 404
|
247
|
+
# GET /hello # 200
|
248
|
+
# GET /hello/world # 404
|
312
249
|
```
|
313
250
|
|
314
251
|
This last example is not a common usage pattern. It's here only to
|
@@ -326,11 +263,8 @@ end
|
|
326
263
|
Cuba.plugin TerminalMatcher
|
327
264
|
|
328
265
|
Cuba.define do
|
329
|
-
res.status = 404
|
330
|
-
|
331
266
|
on get do
|
332
267
|
on terminal("hello") do
|
333
|
-
res.status = 200
|
334
268
|
res.write "hello world"
|
335
269
|
end
|
336
270
|
end
|
@@ -532,46 +466,69 @@ Feel free to store whatever you find convenient.
|
|
532
466
|
Rendering
|
533
467
|
---------
|
534
468
|
|
535
|
-
Cuba
|
536
|
-
[Tilt][tilt],
|
469
|
+
Cuba includes a plugin called `Cuba::Render` that provides a couple of helper
|
470
|
+
methods for rendering templates. This plugin uses [Tilt][tilt], which serves as
|
471
|
+
an interface to a bunch of different Ruby template engines (ERB, Haml, Sass,
|
472
|
+
CoffeeScript, etc.), so you can use the template engine of your choice.
|
537
473
|
|
538
|
-
|
474
|
+
To set up `Cuba::Render`, do:
|
475
|
+
|
476
|
+
```ruby
|
477
|
+
require "cuba"
|
539
478
|
require "cuba/render"
|
479
|
+
require "erb"
|
480
|
+
|
481
|
+
Cuba.plugin(Cuba::Render)
|
482
|
+
```
|
483
|
+
|
484
|
+
This example use ERB, a template engine that comes with Ruby. If you want to
|
485
|
+
use another template engine, one [supported by Tilt][templates], you need to
|
486
|
+
install the required gem and change the `template_engine` setting as shown
|
487
|
+
below.
|
540
488
|
|
541
|
-
|
489
|
+
```ruby
|
490
|
+
Cuba.settings[:render][:template_engine] = "haml"
|
491
|
+
```
|
542
492
|
|
493
|
+
The plugin provides three helper methods for rendering templates: `partial`,
|
494
|
+
`view` and `render`.
|
495
|
+
|
496
|
+
```ruby
|
543
497
|
Cuba.define do
|
544
|
-
on
|
498
|
+
on "about" do
|
499
|
+
# `partial` renders a template called `about.erb` without a layout.
|
500
|
+
res.write partial("about")
|
501
|
+
end
|
545
502
|
|
546
|
-
|
547
|
-
#
|
548
|
-
|
503
|
+
on "home" do
|
504
|
+
# Opposed to `partial`, `view` renders the same template
|
505
|
+
# within a layout called `layout.erb`.
|
506
|
+
res.write view("about")
|
507
|
+
end
|
508
|
+
|
509
|
+
on "contact" do
|
510
|
+
# `render` is a shortcut to `res.write view(...)`
|
511
|
+
render("contact")
|
549
512
|
end
|
550
513
|
end
|
551
514
|
```
|
552
515
|
|
553
|
-
|
554
|
-
|
516
|
+
By default, `Cuba::Render` assumes that all templates are placed in a folder
|
517
|
+
named `views` and that they use the proper extension for the chosen template
|
518
|
+
engine. Also for the `view` and `render` methods, it assumes that the layout
|
519
|
+
template is called `layout`.
|
555
520
|
|
556
|
-
|
557
|
-
and that will allow you to skip the file extension when rendering a
|
558
|
-
file:
|
559
|
-
|
560
|
-
``` ruby
|
561
|
-
require "cuba/render"
|
521
|
+
The defaults can be changed through the `Cuba.settings` method:
|
562
522
|
|
563
|
-
|
564
|
-
Cuba.settings[:render][:template_engine] = "
|
523
|
+
```ruby
|
524
|
+
Cuba.settings[:render][:template_engine] = "haml"
|
525
|
+
Cuba.settings[:render][:views] = "./views/admin/"
|
526
|
+
Cuba.settings[:render][:layout] = "admin"
|
527
|
+
```
|
565
528
|
|
566
|
-
Cuba.
|
567
|
-
on default do
|
529
|
+
NOTE: Cuba doesn't ship with Tilt. You need to install it (`gem install tilt`).
|
568
530
|
|
569
|
-
|
570
|
-
# extension based on the configured template_engine.
|
571
|
-
res.write view("home", content: "hello, world")
|
572
|
-
end
|
573
|
-
end
|
574
|
-
```
|
531
|
+
[templates]: https://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md
|
575
532
|
|
576
533
|
Plugins
|
577
534
|
-------
|
@@ -638,3 +595,26 @@ Cuba.set(:foo, "bar")
|
|
638
595
|
assert_equal "bar", Cuba.get(:foo)
|
639
596
|
assert_equal "bar", Cuba.settings[:foo]
|
640
597
|
```
|
598
|
+
|
599
|
+
Contributing
|
600
|
+
------------
|
601
|
+
|
602
|
+
A good first step is to meet us on IRC and discuss ideas. If that's
|
603
|
+
not possible, you can create an issue explaning the proposed change
|
604
|
+
and a use case. We pay a lot of attention to use cases, because our
|
605
|
+
goal is to keep the code base simple. In many cases, the result of
|
606
|
+
a conversation will be the creation of another tool, instead of the
|
607
|
+
modification of Cuba itself.
|
608
|
+
|
609
|
+
If you want to test Cuba, you may want to use a gemset to isolate
|
610
|
+
the requirements. We recommend the use of tools like [dep][dep] and
|
611
|
+
[gs][gs], but you can use similar tools like [gst][gst] or [bs][bs].
|
612
|
+
|
613
|
+
The required gems for testing and development are listed in the
|
614
|
+
`.gems` file. If you are using [dep][dep], you can create a gemset
|
615
|
+
and run `dep install`.
|
616
|
+
|
617
|
+
[dep]: http://cyx.github.io/dep/
|
618
|
+
[gs]: http://soveran.github.io/gs/
|
619
|
+
[gst]: https://github.com/tonchis/gst
|
620
|
+
[bs]: https://github.com/educabilia/bs
|
data/cuba.gemspec
CHANGED
@@ -1,21 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cuba"
|
3
|
-
s.version = "3.
|
3
|
+
s.version = "3.2.0"
|
4
4
|
s.summary = "Microframework for web applications."
|
5
5
|
s.description = "Cuba is a microframework for web applications."
|
6
6
|
s.authors = ["Michel Martens"]
|
7
7
|
s.email = ["michel@soveran.com"]
|
8
|
-
s.homepage = "
|
8
|
+
s.homepage = "https://github.com/soveran/cuba"
|
9
|
+
s.license = "MIT"
|
9
10
|
|
10
|
-
s.files =
|
11
|
-
"LICENSE",
|
12
|
-
"CHANGELOG",
|
13
|
-
"README.md",
|
14
|
-
"Rakefile",
|
15
|
-
"lib/**/*.rb",
|
16
|
-
"*.gemspec",
|
17
|
-
"test/*.*"
|
18
|
-
]
|
11
|
+
s.files = `git ls-files`.split("\n")
|
19
12
|
|
20
13
|
s.add_dependency "rack"
|
21
14
|
s.add_development_dependency "cutest"
|
data/examples/config.ru
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "../lib/cuba"
|
2
|
+
require "cuba/contrib"
|
3
|
+
|
4
|
+
Cuba.plugin Cuba::Mote
|
5
|
+
|
6
|
+
ITEMS = ("A".."Z").to_a
|
7
|
+
|
8
|
+
Cuba.define do
|
9
|
+
def mote_vars(content)
|
10
|
+
{ content: content }
|
11
|
+
end
|
12
|
+
|
13
|
+
on default do
|
14
|
+
res.write view("home", list: ITEMS)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
run Cuba
|
data/examples/measure.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
require "rack"
|
3
|
+
|
4
|
+
Benchmark.bmbm do |x|
|
5
|
+
|
6
|
+
x.report "Rack::HeaderHash" do
|
7
|
+
1000.times do
|
8
|
+
Rack::Utils::HeaderHash.new("Content-Type" => "text/html")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
x.report "Hash" do
|
13
|
+
1000.times do
|
14
|
+
{ "Content-Type" => "text/html" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "../lib/cuba"
|
2
|
+
require "cuba/contrib"
|
3
|
+
|
4
|
+
Cuba.plugin Cuba::Mote
|
5
|
+
|
6
|
+
ITEMS = ("A".."Z").to_a
|
7
|
+
|
8
|
+
Cuba.send :remove_const, :Response
|
9
|
+
Cuba::Response = Rack::Response
|
10
|
+
|
11
|
+
Cuba.define do
|
12
|
+
def mote_vars(content)
|
13
|
+
{ content: content }
|
14
|
+
end
|
15
|
+
|
16
|
+
on default do
|
17
|
+
res.write view("home", list: ITEMS)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
run Cuba
|
data/lib/cuba.rb
CHANGED
@@ -5,9 +5,10 @@ class Cuba
|
|
5
5
|
class Response
|
6
6
|
attr_accessor :status
|
7
7
|
|
8
|
+
attr :body
|
8
9
|
attr :headers
|
9
10
|
|
10
|
-
def initialize(status =
|
11
|
+
def initialize(status = nil,
|
11
12
|
headers = { "Content-Type" => "text/html; charset=utf-8" })
|
12
13
|
|
13
14
|
@status = status
|
@@ -180,7 +181,15 @@ class Cuba
|
|
180
181
|
# are carried out by #consume.
|
181
182
|
yield(*captures)
|
182
183
|
|
183
|
-
|
184
|
+
if res.status.nil?
|
185
|
+
if res.body.empty?
|
186
|
+
res.status = 404
|
187
|
+
else
|
188
|
+
res.status = 200
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
halt(res.finish)
|
184
193
|
end
|
185
194
|
end
|
186
195
|
|
data/lib/cuba/render.rb
CHANGED
@@ -12,49 +12,51 @@ class Cuba
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def render(template, locals = {}, layout = settings[:render][:layout])
|
16
|
+
res.write(view(template, locals, layout))
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
settings[:render][:views],
|
22
|
-
template,
|
23
|
-
settings[:render][:template_engine]
|
24
|
-
]
|
19
|
+
def view(template, locals = {}, layout = settings[:render][:layout])
|
20
|
+
partial(layout, locals.merge(content: partial(template, locals)))
|
25
21
|
end
|
26
22
|
|
27
23
|
def partial(template, locals = {})
|
28
|
-
|
24
|
+
_render(template_path(template), locals, settings[:render][:options])
|
25
|
+
end
|
26
|
+
|
27
|
+
def template_path(template)
|
28
|
+
dir = settings[:render][:views]
|
29
|
+
ext = settings[:render][:template_engine]
|
30
|
+
|
31
|
+
return File.join(dir, "#{ template }.#{ ext }")
|
29
32
|
end
|
30
33
|
|
31
|
-
#
|
34
|
+
# @private Renders any type of template file supported by Tilt.
|
32
35
|
#
|
33
36
|
# @example
|
34
37
|
#
|
35
38
|
# # Renders home, and is assumed to be HAML.
|
36
|
-
#
|
39
|
+
# _render("home.haml")
|
37
40
|
#
|
38
41
|
# # Renders with some local variables
|
39
|
-
#
|
42
|
+
# _render("home.haml", site_name: "My Site")
|
40
43
|
#
|
41
44
|
# # Renders with HAML options
|
42
|
-
#
|
45
|
+
# _render("home.haml", {}, ugly: true, format: :html5)
|
43
46
|
#
|
44
47
|
# # Renders in layout
|
45
|
-
#
|
48
|
+
# _render("layout.haml") { _render("home.haml") }
|
46
49
|
#
|
47
|
-
def
|
50
|
+
def _render(template, locals = {}, options = {}, &block)
|
48
51
|
_cache.fetch(template) {
|
49
52
|
Tilt.new(template, 1, options.merge(outvar: '@_output'))
|
50
53
|
}.render(self, locals, &block)
|
51
54
|
end
|
52
55
|
|
53
|
-
# @private Used internally by #
|
56
|
+
# @private Used internally by #_render to cache the
|
54
57
|
# Tilt templates.
|
55
58
|
def _cache
|
56
59
|
Thread.current[:_cache] ||= Tilt::Cache.new
|
57
60
|
end
|
58
|
-
private :_cache
|
59
61
|
end
|
60
62
|
end
|
data/makefile
ADDED
data/test/integration.rb
CHANGED
data/test/on.rb
CHANGED
@@ -95,3 +95,63 @@ test "reverts a half-met matcher" do
|
|
95
95
|
assert_equal "/post", env["PATH_INFO"]
|
96
96
|
assert_equal "/", env["SCRIPT_NAME"]
|
97
97
|
end
|
98
|
+
|
99
|
+
test "responds 404 if conditions are not met" do
|
100
|
+
Cuba.define do
|
101
|
+
on root do
|
102
|
+
res.write("Should be unmet")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
env = { "PATH_INFO" => "/notexists", "SCRIPT_NAME" => "/" }
|
107
|
+
status, _, body = Cuba.call(env)
|
108
|
+
|
109
|
+
assert_equal 404, status
|
110
|
+
assert body.empty?
|
111
|
+
end
|
112
|
+
|
113
|
+
test "responds 404 if nested conditions are not met" do
|
114
|
+
Cuba.define do
|
115
|
+
on get do
|
116
|
+
on root do
|
117
|
+
res.write("Should be unmet")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
on default do
|
122
|
+
res.write("Should be unmet")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
env = {
|
127
|
+
"REQUEST_METHOD" => "GET",
|
128
|
+
"PATH_INFO" => "/notexists",
|
129
|
+
"SCRIPT_NAME" => "/"
|
130
|
+
}
|
131
|
+
|
132
|
+
status, _, body = Cuba.call(env)
|
133
|
+
|
134
|
+
assert_equal 404, status
|
135
|
+
assert body.empty?
|
136
|
+
end
|
137
|
+
|
138
|
+
test "responds 200 even with an empty body if status is set" do
|
139
|
+
Cuba.define do
|
140
|
+
on get do
|
141
|
+
on root do
|
142
|
+
res.status = 200
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
env = {
|
148
|
+
"REQUEST_METHOD" => "GET",
|
149
|
+
"PATH_INFO" => "/",
|
150
|
+
"SCRIPT_NAME" => "/"
|
151
|
+
}
|
152
|
+
|
153
|
+
status, _, body = Cuba.call(env)
|
154
|
+
|
155
|
+
assert_equal 200, status
|
156
|
+
assert body.empty?
|
157
|
+
end
|
data/test/render.rb
CHANGED
@@ -28,6 +28,10 @@ scope do
|
|
28
28
|
on "about" do
|
29
29
|
res.write partial("about", title: "About Cuba")
|
30
30
|
end
|
31
|
+
|
32
|
+
on "render" do
|
33
|
+
render("about", title: "About Cuba")
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
@@ -43,6 +47,12 @@ scope do
|
|
43
47
|
assert_response body, ["<title>Cuba: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>\n"]
|
44
48
|
end
|
45
49
|
|
50
|
+
test "render" do
|
51
|
+
_, _, body = Cuba.call({ "PATH_INFO" => "/render", "SCRIPT_NAME" => "/" })
|
52
|
+
|
53
|
+
assert_response body, ["<title>Cuba: About Cuba</title>\n<h1>About Cuba</h1>\n"]
|
54
|
+
end
|
55
|
+
|
46
56
|
test "partial with str as engine" do
|
47
57
|
Cuba.settings[:render][:template_engine] = "str"
|
48
58
|
|
@@ -87,22 +97,6 @@ test "caching behavior" do
|
|
87
97
|
assert_equal 1, Thread.current[:_cache].instance_variable_get(:@cache).size
|
88
98
|
end
|
89
99
|
|
90
|
-
test "simple layout support" do
|
91
|
-
Cuba.plugin Cuba::Render
|
92
|
-
|
93
|
-
Cuba.define do
|
94
|
-
on true do
|
95
|
-
res.write render("test/views/layout-yield.erb") {
|
96
|
-
render("test/views/content-yield.erb")
|
97
|
-
}
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
_, _, resp = Cuba.call({})
|
102
|
-
|
103
|
-
assert_response resp, ["Header\nThis is the actual content.\nFooter\n"]
|
104
|
-
end
|
105
|
-
|
106
100
|
test "overrides layout" do
|
107
101
|
Cuba.plugin Cuba::Render
|
108
102
|
Cuba.settings[:render][:views] = "./test/views"
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= title %></h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>#{title}</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
This is the actual content.
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Abs Path</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>{{ foo }}</h1>
|
data/test/views/home.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Home</h1>
|
data/test/views/home.str
ADDED
data/test/views/test.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Displaying {{ i }}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -73,15 +73,22 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
76
|
+
- .gems
|
77
|
+
- .gitignore
|
77
78
|
- CHANGELOG
|
79
|
+
- LICENSE
|
78
80
|
- README.md
|
79
|
-
-
|
81
|
+
- cuba.gemspec
|
82
|
+
- examples/config.ru
|
83
|
+
- examples/measure.rb
|
84
|
+
- examples/rack-response.ru
|
85
|
+
- examples/views/home.mote
|
86
|
+
- examples/views/layout.mote
|
87
|
+
- lib/cuba.rb
|
80
88
|
- lib/cuba/capybara.rb
|
81
89
|
- lib/cuba/render.rb
|
82
90
|
- lib/cuba/test.rb
|
83
|
-
-
|
84
|
-
- cuba.gemspec
|
91
|
+
- makefile
|
85
92
|
- test/accept.rb
|
86
93
|
- test/captures.rb
|
87
94
|
- test/composition.rb
|
@@ -105,8 +112,23 @@ files:
|
|
105
112
|
- test/segment.rb
|
106
113
|
- test/session.rb
|
107
114
|
- test/settings.rb
|
108
|
-
|
109
|
-
|
115
|
+
- test/views/about.erb
|
116
|
+
- test/views/about.str
|
117
|
+
- test/views/content-yield.erb
|
118
|
+
- test/views/custom/abs_path.mote
|
119
|
+
- test/views/frag.mote
|
120
|
+
- test/views/home.erb
|
121
|
+
- test/views/home.mote
|
122
|
+
- test/views/home.str
|
123
|
+
- test/views/layout-alternative.erb
|
124
|
+
- test/views/layout-yield.erb
|
125
|
+
- test/views/layout.erb
|
126
|
+
- test/views/layout.mote
|
127
|
+
- test/views/layout.str
|
128
|
+
- test/views/test.erb
|
129
|
+
homepage: https://github.com/soveran/cuba
|
130
|
+
licenses:
|
131
|
+
- MIT
|
110
132
|
metadata: {}
|
111
133
|
post_install_message:
|
112
134
|
rdoc_options: []
|