roda 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/doc/release_notes/2.8.0.txt +44 -0
- data/lib/roda/plugins/content_for.rb +10 -9
- data/lib/roda/plugins/multi_view.rb +80 -0
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/content_for_spec.rb +63 -5
- data/spec/plugin/multi_view_spec.rb +50 -0
- data/spec/views/a.erb +1 -0
- data/spec/views/b.erb +1 -0
- data/spec/views/c.erb +1 -0
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49da3db12f5573c87c6be816d293503ff794ea2f
|
4
|
+
data.tar.gz: 443753193002f7e346437cd50ed50eab168e8f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0be145864376662bc858c903c9d4a1865b184b782b2b3f0494c0e85f168de74f44fe8c58f7398e6c1236cbbf9f280a22c3658bdf8a83f0018c6a9af45a1dc62
|
7
|
+
data.tar.gz: 79911454fded94aaf16e48ed958c0ebfaf7d0bb5e3be9e22e0740b71eb21f5acabf949eff65eba5314a0b67dfeca13b84e4037484efff44fbc7d6d382061115b
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 2.8.0 (2015-11-16)
|
2
|
+
|
3
|
+
* Add multi_view plugin for easily setting up routing for rendering multiple views (jeremyevans)
|
4
|
+
|
5
|
+
* Make content_for plugin work with haml and potentially other non-erb template engines (plukevdh) (#50)
|
6
|
+
|
1
7
|
= 2.7.0 (2015-10-13)
|
2
8
|
|
3
9
|
* Add run_handler plugin for modifying rack response arrays when using r.run, and continuing routing for 404 responses (jeremyevans)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A multi_view plugin has been added, for easily setting up routing
|
4
|
+
for rendering multiple views:
|
5
|
+
|
6
|
+
plugin :multi_view
|
7
|
+
|
8
|
+
route do |r|
|
9
|
+
r.multi_view(['foo', 'bar', 'baz'])
|
10
|
+
end
|
11
|
+
|
12
|
+
# or:
|
13
|
+
|
14
|
+
route do |r|
|
15
|
+
r.multi_view(/(foo|bar|baz)/)
|
16
|
+
end
|
17
|
+
|
18
|
+
# or:
|
19
|
+
|
20
|
+
regexp = multi_view_compile(['foo', 'bar', 'baz'])
|
21
|
+
route do |r|
|
22
|
+
r.multi_view(regexp)
|
23
|
+
end
|
24
|
+
|
25
|
+
# all are equivalent to:
|
26
|
+
|
27
|
+
route do |r|
|
28
|
+
r.get 'foo' do
|
29
|
+
view('foo')
|
30
|
+
end
|
31
|
+
|
32
|
+
r.get 'bar' do
|
33
|
+
view('bar')
|
34
|
+
end
|
35
|
+
|
36
|
+
r.get 'baz' do
|
37
|
+
view('baz')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
= Other Improvements
|
42
|
+
|
43
|
+
* The content_for plugin now supports haml templates. Previous only
|
44
|
+
erb templates were supported.
|
@@ -7,10 +7,8 @@ class Roda
|
|
7
7
|
# can set content for the layout template to display outside
|
8
8
|
# of the normal content pane.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# +:outvar+ render option. In the template in which you
|
13
|
-
# want to store content, call content_for with a block:
|
10
|
+
# In the template in which you want to store content, call
|
11
|
+
# content_for with a block:
|
14
12
|
#
|
15
13
|
# <% content_for :foo do %>
|
16
14
|
# Some content here.
|
@@ -34,12 +32,15 @@ class Roda
|
|
34
32
|
# is no content stored with that key.
|
35
33
|
def content_for(key, &block)
|
36
34
|
if block
|
35
|
+
outvar = render_opts[:template_opts][:outvar]
|
36
|
+
buf_was = instance_variable_get(outvar)
|
37
|
+
# clean the output buffer for ERB-based rendering systems
|
38
|
+
instance_variable_set(outvar, '')
|
39
|
+
|
37
40
|
@_content_for ||= {}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@_content_for[key] = @_out_buf
|
42
|
-
@_out_buf = buf_was
|
41
|
+
@_content_for[key] = Tilt[render_opts[:engine]].new(&block).render
|
42
|
+
|
43
|
+
instance_variable_set(outvar, buf_was)
|
43
44
|
elsif @_content_for
|
44
45
|
@_content_for[key]
|
45
46
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class Roda
|
2
|
+
module RodaPlugins
|
3
|
+
# The multi_view plugin makes it easy to render multiple views, where the
|
4
|
+
# view template is the same as the matched element. It adds an +r.multi_view+
|
5
|
+
# method, which takes an argument that is passed to +r.get+, and should
|
6
|
+
# capture a single argument, which is treated as the template name to pass
|
7
|
+
# to +view+. This makes it possible to pass in an array of strings, or a
|
8
|
+
# regexp with a single capture.
|
9
|
+
#
|
10
|
+
# The advantage of using a regexp over an array of strings is that the regexp
|
11
|
+
# is generally faster and uses less memory. However, constructing the regexps
|
12
|
+
# is more cumbersome. To make it easier, the multi_view plugin also offers a
|
13
|
+
# +multi_view_compile+ class method that will take an array of view template
|
14
|
+
# names and construct a regexp that can be passed to +r.multi_view+.
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
#
|
18
|
+
# plugin :multi_view
|
19
|
+
#
|
20
|
+
# route do |r|
|
21
|
+
# r.multi_view(['foo', 'bar', 'baz'])
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # or:
|
25
|
+
#
|
26
|
+
# route do |r|
|
27
|
+
# r.multi_view(/(foo|bar|baz)/)
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # or:
|
31
|
+
#
|
32
|
+
# regexp = multi_view_compile(['foo', 'bar', 'baz'])
|
33
|
+
# route do |r|
|
34
|
+
# r.multi_view(regexp)
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# # all are equivalent to:
|
38
|
+
#
|
39
|
+
# route do |r|
|
40
|
+
# r.get 'foo' do
|
41
|
+
# view('foo')
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# r.get 'bar' do
|
45
|
+
# view('bar')
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# r.get 'baz' do
|
49
|
+
# view('baz')
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
module MultiView
|
53
|
+
# Depend on the render plugin, since this plugin only makes
|
54
|
+
# sense when the render plugin is used.
|
55
|
+
def self.load_dependencies(app)
|
56
|
+
app.plugin :render
|
57
|
+
end
|
58
|
+
|
59
|
+
module ClassMethods
|
60
|
+
# Given the array of view template names, return a regexp that will
|
61
|
+
# match on any of the names and capture the matched name.
|
62
|
+
def multi_view_compile(array)
|
63
|
+
/(#{Regexp.union(array)})/
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module RequestMethods
|
68
|
+
# Pass the argument to +get+, and assume if the matchers match that
|
69
|
+
# there is one capture, and call view with that capture.
|
70
|
+
def multi_view(arg)
|
71
|
+
get(arg) do |page|
|
72
|
+
scope.view(page)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
register_plugin(:multi_view, MultiView)
|
79
|
+
end
|
80
|
+
end
|
data/lib/roda/version.rb
CHANGED
@@ -2,21 +2,22 @@ require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'tilt/erb'
|
5
|
+
require 'tilt/haml'
|
5
6
|
rescue LoadError
|
6
|
-
warn "tilt not installed, skipping content_for plugin test"
|
7
|
+
warn "tilt, erb, or haml not installed, skipping content_for plugin test"
|
7
8
|
else
|
8
|
-
describe "content_for plugin" do
|
9
|
+
describe "content_for plugin with erb" do
|
9
10
|
before do
|
10
11
|
app(:bare) do
|
11
|
-
plugin :render, :views=>'./spec/views'
|
12
|
+
plugin :render, :views => './spec/views'
|
12
13
|
plugin :content_for
|
13
14
|
|
14
15
|
route do |r|
|
15
16
|
r.root do
|
16
|
-
view(:inline=>"<% content_for :foo do %>foo<% end %>bar", :layout=>{:inline=>'<%= yield %> <%= content_for(:foo) %>'})
|
17
|
+
view(:inline => "<% content_for :foo do %>foo<% end %>bar", :layout => { :inline => '<%= yield %> <%= content_for(:foo) %>' })
|
17
18
|
end
|
18
19
|
r.get 'a' do
|
19
|
-
view(:inline=>"bar", :layout=>{:inline=>'<%= content_for(:foo) %> <%= yield %>'})
|
20
|
+
view(:inline => "bar", :layout => { :inline => '<%= content_for(:foo) %> <%= yield %>' })
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -30,4 +31,61 @@ describe "content_for plugin" do
|
|
30
31
|
body('/a').strip.must_equal "bar"
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
describe "content_for plugin with haml" do
|
36
|
+
before do
|
37
|
+
app(:bare) do
|
38
|
+
plugin :render, :engine => 'haml'
|
39
|
+
plugin :content_for
|
40
|
+
|
41
|
+
route do |r|
|
42
|
+
r.root do
|
43
|
+
view(:inline => "- content_for :foo do\n - capture_haml do\n foo\nbar", :layout => { :inline => "= yield\n=content_for :foo" })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should work with alternate rendering engines" do
|
50
|
+
body.strip.must_equal "bar\nfoo"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "content_for plugin with mixed template engines" do
|
55
|
+
before do
|
56
|
+
app(:bare) do
|
57
|
+
plugin :render, :layout_opts=>{:engine => 'haml', :inline => "= yield\n=content_for :foo" }
|
58
|
+
plugin :content_for
|
59
|
+
|
60
|
+
route do |r|
|
61
|
+
r.root do
|
62
|
+
view(:inline => "<% content_for :foo do %>foo<% end %>bar")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should work with alternate rendering engines" do
|
69
|
+
body.strip.must_equal "bar\nfoo"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "content_for plugin when overriding :engine" do
|
74
|
+
before do
|
75
|
+
app(:bare) do
|
76
|
+
plugin :render, :engine => 'haml', :layout_opts=>{:inline => "= yield\n=content_for :foo" }
|
77
|
+
plugin :content_for
|
78
|
+
|
79
|
+
route do |r|
|
80
|
+
r.root do
|
81
|
+
view(:inline => "<% content_for :foo do %>foo<% end %>bar", :engine=>:erb)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should work with alternate rendering engines" do
|
88
|
+
body.strip.must_equal "bar\nfoo"
|
89
|
+
end
|
90
|
+
end
|
33
91
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'tilt/erb'
|
5
|
+
rescue LoadError
|
6
|
+
warn "tilt not installed, skipping multi_view plugin test"
|
7
|
+
else
|
8
|
+
describe "multi_view plugin" do
|
9
|
+
before do
|
10
|
+
app(:bare) do
|
11
|
+
plugin :render, :views=>'spec/views', :layout=>'layout-yield'
|
12
|
+
plugin :multi_view
|
13
|
+
|
14
|
+
route do |r|
|
15
|
+
r.multi_view(['a', 'b', 'c'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "supports easy rendering of multiple views by name" do
|
21
|
+
body('/a').gsub(/\s+/, '').must_equal "HeaderaFooter"
|
22
|
+
body('/b').gsub(/\s+/, '').must_equal "HeaderbFooter"
|
23
|
+
body('/c').gsub(/\s+/, '').must_equal "HeadercFooter"
|
24
|
+
status('/d').must_equal 404
|
25
|
+
status('/a', 'REQUEST_METHOD'=>'POST').must_equal 404
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "multi_view plugin multi_view_compile method " do
|
30
|
+
before do
|
31
|
+
app(:bare) do
|
32
|
+
plugin :render, :views=>'spec/views', :layout=>'layout-yield'
|
33
|
+
plugin :multi_view
|
34
|
+
regexp = multi_view_compile(['a', 'b', 'c'])
|
35
|
+
|
36
|
+
route do |r|
|
37
|
+
r.multi_view(regexp)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "supports easy rendering of multiple views by name" do
|
43
|
+
body('/a').gsub(/\s+/, '').must_equal "HeaderaFooter"
|
44
|
+
body('/b').gsub(/\s+/, '').must_equal "HeaderbFooter"
|
45
|
+
body('/c').gsub(/\s+/, '').must_equal "HeadercFooter"
|
46
|
+
status('/d').must_equal 404
|
47
|
+
status('/a', 'REQUEST_METHOD'=>'POST').must_equal 404
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/views/a.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
a
|
data/spec/views/b.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
b
|
data/spec/views/c.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
c
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: haml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rack_csrf
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +173,7 @@ extra_rdoc_files:
|
|
145
173
|
- doc/release_notes/2.5.1.txt
|
146
174
|
- doc/release_notes/2.6.0.txt
|
147
175
|
- doc/release_notes/2.7.0.txt
|
176
|
+
- doc/release_notes/2.8.0.txt
|
148
177
|
files:
|
149
178
|
- CHANGELOG
|
150
179
|
- MIT-LICENSE
|
@@ -164,6 +193,7 @@ files:
|
|
164
193
|
- doc/release_notes/2.5.1.txt
|
165
194
|
- doc/release_notes/2.6.0.txt
|
166
195
|
- doc/release_notes/2.7.0.txt
|
196
|
+
- doc/release_notes/2.8.0.txt
|
167
197
|
- lib/roda.rb
|
168
198
|
- lib/roda/plugins/_erubis_escaping.rb
|
169
199
|
- lib/roda/plugins/all_verbs.rb
|
@@ -202,6 +232,7 @@ files:
|
|
202
232
|
- lib/roda/plugins/module_include.rb
|
203
233
|
- lib/roda/plugins/multi_route.rb
|
204
234
|
- lib/roda/plugins/multi_run.rb
|
235
|
+
- lib/roda/plugins/multi_view.rb
|
205
236
|
- lib/roda/plugins/named_templates.rb
|
206
237
|
- lib/roda/plugins/not_allowed.rb
|
207
238
|
- lib/roda/plugins/not_found.rb
|
@@ -278,6 +309,7 @@ files:
|
|
278
309
|
- spec/plugin/module_include_spec.rb
|
279
310
|
- spec/plugin/multi_route_spec.rb
|
280
311
|
- spec/plugin/multi_run_spec.rb
|
312
|
+
- spec/plugin/multi_view_spec.rb
|
281
313
|
- spec/plugin/named_templates_spec.rb
|
282
314
|
- spec/plugin/not_allowed_spec.rb
|
283
315
|
- spec/plugin/not_found_spec.rb
|
@@ -312,8 +344,11 @@ files:
|
|
312
344
|
- spec/spec_helper.rb
|
313
345
|
- spec/version_spec.rb
|
314
346
|
- spec/views/_test.erb
|
347
|
+
- spec/views/a.erb
|
315
348
|
- spec/views/about.erb
|
316
349
|
- spec/views/about.str
|
350
|
+
- spec/views/b.erb
|
351
|
+
- spec/views/c.erb
|
317
352
|
- spec/views/content-yield.erb
|
318
353
|
- spec/views/home.erb
|
319
354
|
- spec/views/home.str
|