roda 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +24 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -4
- data/doc/release_notes/2.0.0.txt +75 -0
- data/lib/roda/plugins/assets.rb +2 -2
- data/lib/roda/plugins/backtracking_array.rb +2 -11
- data/lib/roda/plugins/caching.rb +4 -2
- data/lib/roda/plugins/chunked.rb +4 -9
- data/lib/roda/plugins/class_level_routing.rb +1 -3
- data/lib/roda/plugins/default_headers.rb +1 -2
- data/lib/roda/plugins/error_email.rb +4 -14
- data/lib/roda/plugins/error_handler.rb +4 -4
- data/lib/roda/plugins/flash.rb +1 -3
- data/lib/roda/plugins/halt.rb +24 -5
- data/lib/roda/plugins/header_matchers.rb +2 -7
- data/lib/roda/plugins/hooks.rb +1 -3
- data/lib/roda/plugins/json.rb +4 -2
- data/lib/roda/plugins/mailer.rb +8 -7
- data/lib/roda/plugins/middleware.rb +21 -9
- data/lib/roda/plugins/not_found.rb +3 -3
- data/lib/roda/plugins/padrino_render.rb +60 -0
- data/lib/roda/plugins/param_matchers.rb +3 -3
- data/lib/roda/plugins/path.rb +2 -1
- data/lib/roda/plugins/render.rb +55 -37
- data/lib/roda/plugins/render_each.rb +4 -2
- data/lib/roda/plugins/static_path_info.rb +2 -63
- data/lib/roda/plugins/streaming.rb +4 -2
- data/lib/roda/version.rb +2 -2
- data/lib/roda.rb +71 -172
- data/spec/matchers_spec.rb +31 -82
- data/spec/plugin/assets_spec.rb +6 -6
- data/spec/plugin/error_handler_spec.rb +23 -0
- data/spec/plugin/halt_spec.rb +39 -0
- data/spec/plugin/middleware_spec.rb +7 -0
- data/spec/plugin/padrino_render_spec.rb +57 -0
- data/spec/plugin/render_each_spec.rb +1 -1
- data/spec/plugin/render_spec.rb +59 -5
- data/spec/request_spec.rb +0 -12
- data/spec/response_spec.rb +0 -24
- data/spec/views/_test.erb +1 -0
- metadata +7 -4
- data/lib/roda/plugins/delete_nil_headers.rb +0 -34
- data/spec/module_spec.rb +0 -29
@@ -49,4 +49,11 @@ describe "middleware plugin" do
|
|
49
49
|
body('/a', 'REQUEST_METHOD'=>'PATCH').should == 'a2'
|
50
50
|
body('/b', 'REQUEST_METHOD'=>'PATCH').should == 'b1'
|
51
51
|
end
|
52
|
+
|
53
|
+
it "makes it still possible to use the Roda app normally" do
|
54
|
+
app(:middleware) do
|
55
|
+
"a"
|
56
|
+
end
|
57
|
+
body.should == 'a'
|
58
|
+
end
|
52
59
|
end
|
@@ -0,0 +1,57 @@
|
|
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 padrino_render plugin test"
|
7
|
+
else
|
8
|
+
describe "padrino_render plugin" do
|
9
|
+
before do
|
10
|
+
app(:bare) do
|
11
|
+
plugin :padrino_render, :views=>"./spec/views"
|
12
|
+
|
13
|
+
route do |r|
|
14
|
+
r.is "partial" do
|
15
|
+
partial("test", :locals=>{:title => "About Roda"})
|
16
|
+
end
|
17
|
+
|
18
|
+
r.is "partial/subdir" do
|
19
|
+
partial("about/test", :locals=>{:title => "About Roda"})
|
20
|
+
end
|
21
|
+
|
22
|
+
r.is "partial/inline" do
|
23
|
+
partial(:inline=>"Hello <%= name %>", :locals=>{:name => "Agent Smith"})
|
24
|
+
end
|
25
|
+
|
26
|
+
r.is "render" do
|
27
|
+
render(:content=>'bar', :layout_opts=>{:locals=>{:title=>"Home"}})
|
28
|
+
end
|
29
|
+
|
30
|
+
r.is "render/nolayout" do
|
31
|
+
render("about", :locals=>{:title => "No Layout"}, :layout=>nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "partial renders without layout, and prepends _ to template" do
|
38
|
+
body("/partial").strip.should == "<h1>About Roda</h1>"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "partial renders without layout, and prepends _ to template" do
|
42
|
+
body("/partial/subdir").strip.should == "<h1>Subdir: About Roda</h1>"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "partial handles inline partials" do
|
46
|
+
body("/partial/inline").strip.should == "Hello Agent Smith"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "render uses layout by default" do
|
50
|
+
body("/render").strip.should == "<title>Roda: Home</title>\nbar"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "render doesn't use layout if layout is nil" do
|
54
|
+
body("/render/nolayout").strip.should == "<h1>No Layout</h1>"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -4,7 +4,7 @@ describe "render_each plugin" do
|
|
4
4
|
it "calls render with each argument, returning joined string with all results" do
|
5
5
|
app(:bare) do
|
6
6
|
plugin :render_each
|
7
|
-
def
|
7
|
+
def render_template(t, opts)
|
8
8
|
"r#{t}#{opts[:locals][:foo] if opts[:locals]}#{opts[:bar]}#{opts[:locals][:bar] if opts[:locals]} "
|
9
9
|
end
|
10
10
|
|
data/spec/plugin/render_spec.rb
CHANGED
@@ -107,6 +107,62 @@ describe "render plugin" do
|
|
107
107
|
body.strip.should == "<title>Alternative Layout: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
|
108
108
|
end
|
109
109
|
|
110
|
+
it ":layout=>true/false/string/hash/not-present respects plugin layout switch and template" do
|
111
|
+
app(:bare) do
|
112
|
+
plugin :render, :views=>"./spec/views", :layout_opts=>{:template=>'layout-yield', :locals=>{:title=>'a'}}
|
113
|
+
|
114
|
+
route do |r|
|
115
|
+
opts = {:content=>'bar'}
|
116
|
+
opts[:layout] = true if r.path == '/'
|
117
|
+
opts[:layout] = false if r.path == '/f'
|
118
|
+
opts[:layout] = 'layout' if r.path == '/s'
|
119
|
+
opts[:layout] = {:template=>'layout'} if r.path == '/h'
|
120
|
+
view(opts)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
body.gsub("\n", '').should == "HeaderbarFooter"
|
125
|
+
body('/a').gsub("\n", '').should == "HeaderbarFooter"
|
126
|
+
body('/f').gsub("\n", '').should == "bar"
|
127
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
128
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
129
|
+
|
130
|
+
app.plugin :render
|
131
|
+
body.gsub("\n", '').should == "HeaderbarFooter"
|
132
|
+
body('/a').gsub("\n", '').should == "HeaderbarFooter"
|
133
|
+
body('/f').gsub("\n", '').should == "bar"
|
134
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
135
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
136
|
+
|
137
|
+
app.plugin :render, :layout=>true
|
138
|
+
body.gsub("\n", '').should == "HeaderbarFooter"
|
139
|
+
body('/a').gsub("\n", '').should == "HeaderbarFooter"
|
140
|
+
body('/f').gsub("\n", '').should == "bar"
|
141
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
142
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
143
|
+
|
144
|
+
app.plugin :render, :layout=>'layout-alternative'
|
145
|
+
body.gsub("\n", '').should == "<title>Alternative Layout: a</title>bar"
|
146
|
+
body('/a').gsub("\n", '').should == "<title>Alternative Layout: a</title>bar"
|
147
|
+
body('/f').gsub("\n", '').should == "bar"
|
148
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
149
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
150
|
+
|
151
|
+
app.plugin :render, :layout=>nil
|
152
|
+
body.gsub("\n", '').should == "<title>Alternative Layout: a</title>bar"
|
153
|
+
body('/a').gsub("\n", '').should == "bar"
|
154
|
+
body('/f').gsub("\n", '').should == "bar"
|
155
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
156
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
157
|
+
|
158
|
+
app.plugin :render, :layout=>false
|
159
|
+
body.gsub("\n", '').should == "<title>Alternative Layout: a</title>bar"
|
160
|
+
body('/a').gsub("\n", '').should == "bar"
|
161
|
+
body('/f').gsub("\n", '').should == "bar"
|
162
|
+
body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
163
|
+
body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar"
|
164
|
+
end
|
165
|
+
|
110
166
|
it "inline layouts and inline views" do
|
111
167
|
app(:render) do
|
112
168
|
view({:inline=>'bar'}, :layout=>{:inline=>'Foo: <%= yield %>'})
|
@@ -141,7 +197,7 @@ describe "render plugin" do
|
|
141
197
|
body.should == "i1"
|
142
198
|
end
|
143
199
|
|
144
|
-
it "template cache respects :
|
200
|
+
it "template cache respects :template_opts" do
|
145
201
|
c = Class.new do
|
146
202
|
def initialize(path, _, opts)
|
147
203
|
@path = path
|
@@ -154,10 +210,10 @@ describe "render plugin" do
|
|
154
210
|
|
155
211
|
app(:render) do |r|
|
156
212
|
r.is "a" do
|
157
|
-
render(:inline=>"i", :template_class=>c, :
|
213
|
+
render(:inline=>"i", :template_class=>c, :template_opts=>{:foo=>'a'})
|
158
214
|
end
|
159
215
|
r.is "b" do
|
160
|
-
render(:inline=>"i", :template_class=>c, :
|
216
|
+
render(:inline=>"i", :template_class=>c, :template_opts=>{:foo=>'b'})
|
161
217
|
end
|
162
218
|
end
|
163
219
|
|
@@ -195,8 +251,6 @@ describe "render plugin" do
|
|
195
251
|
sc = Class.new(c)
|
196
252
|
|
197
253
|
c.render_opts.should_not equal(sc.render_opts)
|
198
|
-
c.render_opts[:layout_opts].should_not equal(sc.render_opts[:layout_opts])
|
199
|
-
c.render_opts[:template_opts].should_not equal(sc.render_opts[:template_opts])
|
200
254
|
c.render_opts[:cache].should_not equal(sc.render_opts[:cache])
|
201
255
|
end
|
202
256
|
|
data/spec/request_spec.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
2
|
|
3
|
-
describe "request.full_path_info" do
|
4
|
-
it "should return the script name and path_info as a string" do
|
5
|
-
app do |r|
|
6
|
-
r.on "foo" do
|
7
|
-
"#{r.full_path_info}:#{r.script_name}:#{r.path_info}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
body("/foo/bar").should == "/foo/bar:/foo:/bar"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
3
|
describe "request.path, .remaining_path, and .matched_path" do
|
16
4
|
it "should return the script name and path_info as a string" do
|
17
5
|
app do |r|
|
data/spec/response_spec.rb
CHANGED
@@ -1,29 +1,5 @@
|
|
1
1
|
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
2
|
|
3
|
-
describe "cookie handling" do
|
4
|
-
it "should set cookies on response" do
|
5
|
-
app do |r|
|
6
|
-
response.set_cookie("foo", "bar")
|
7
|
-
response.set_cookie("bar", "baz")
|
8
|
-
"Hello"
|
9
|
-
end
|
10
|
-
|
11
|
-
header('Set-Cookie').should == "foo=bar\nbar=baz"
|
12
|
-
body.should == 'Hello'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should delete cookies on response" do
|
16
|
-
app do |r|
|
17
|
-
response.set_cookie("foo", "bar")
|
18
|
-
response.delete_cookie("foo")
|
19
|
-
"Hello"
|
20
|
-
end
|
21
|
-
|
22
|
-
header('Set-Cookie').should =~ /foo=; (max-age=0; )?expires=Thu, 01[ -]Jan[ -]1970 00:00:00 (-0000|GMT)/
|
23
|
-
body.should == 'Hello'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
3
|
describe "response #[] and #[]=" do
|
28
4
|
it "should get/set headers" do
|
29
5
|
app do |r|
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= title %></h1>
|
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:
|
4
|
+
version: 2.0.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-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -136,6 +136,7 @@ extra_rdoc_files:
|
|
136
136
|
- doc/release_notes/1.1.0.txt
|
137
137
|
- doc/release_notes/1.2.0.txt
|
138
138
|
- doc/release_notes/1.3.0.txt
|
139
|
+
- doc/release_notes/2.0.0.txt
|
139
140
|
files:
|
140
141
|
- CHANGELOG
|
141
142
|
- MIT-LICENSE
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- doc/release_notes/1.1.0.txt
|
147
148
|
- doc/release_notes/1.2.0.txt
|
148
149
|
- doc/release_notes/1.3.0.txt
|
150
|
+
- doc/release_notes/2.0.0.txt
|
149
151
|
- lib/roda.rb
|
150
152
|
- lib/roda/plugins/_erubis_escaping.rb
|
151
153
|
- lib/roda/plugins/all_verbs.rb
|
@@ -161,7 +163,6 @@ files:
|
|
161
163
|
- lib/roda/plugins/delay_build.rb
|
162
164
|
- lib/roda/plugins/delegate.rb
|
163
165
|
- lib/roda/plugins/delete_empty_headers.rb
|
164
|
-
- lib/roda/plugins/delete_nil_headers.rb
|
165
166
|
- lib/roda/plugins/drop_body.rb
|
166
167
|
- lib/roda/plugins/empty_root.rb
|
167
168
|
- lib/roda/plugins/environments.rb
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- lib/roda/plugins/named_templates.rb
|
186
187
|
- lib/roda/plugins/not_allowed.rb
|
187
188
|
- lib/roda/plugins/not_found.rb
|
189
|
+
- lib/roda/plugins/padrino_render.rb
|
188
190
|
- lib/roda/plugins/param_matchers.rb
|
189
191
|
- lib/roda/plugins/pass.rb
|
190
192
|
- lib/roda/plugins/path.rb
|
@@ -209,7 +211,6 @@ files:
|
|
209
211
|
- spec/freeze_spec.rb
|
210
212
|
- spec/integration_spec.rb
|
211
213
|
- spec/matchers_spec.rb
|
212
|
-
- spec/module_spec.rb
|
213
214
|
- spec/opts_spec.rb
|
214
215
|
- spec/plugin/_erubis_escaping_spec.rb
|
215
216
|
- spec/plugin/all_verbs_spec.rb
|
@@ -248,6 +249,7 @@ files:
|
|
248
249
|
- spec/plugin/named_templates_spec.rb
|
249
250
|
- spec/plugin/not_allowed_spec.rb
|
250
251
|
- spec/plugin/not_found_spec.rb
|
252
|
+
- spec/plugin/padrino_render_spec.rb
|
251
253
|
- spec/plugin/param_matchers_spec.rb
|
252
254
|
- spec/plugin/pass_spec.rb
|
253
255
|
- spec/plugin/path_matchers_spec.rb
|
@@ -269,6 +271,7 @@ files:
|
|
269
271
|
- spec/session_spec.rb
|
270
272
|
- spec/spec_helper.rb
|
271
273
|
- spec/version_spec.rb
|
274
|
+
- spec/views/_test.erb
|
272
275
|
- spec/views/about.erb
|
273
276
|
- spec/views/about.str
|
274
277
|
- spec/views/content-yield.erb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
class Roda
|
2
|
-
module RodaPlugins
|
3
|
-
# The delete_nil_headers plugin deletes any headers whose
|
4
|
-
# value is set to nil. Because of how default headers are
|
5
|
-
# set in Roda, if you have a default header but don't want
|
6
|
-
# to set it for a specific request, you need to use this plugin
|
7
|
-
# and set the value to nil so that
|
8
|
-
#
|
9
|
-
# The following example will return "<foo>" as the body.
|
10
|
-
#
|
11
|
-
# plugin :h
|
12
|
-
#
|
13
|
-
# route do |r|
|
14
|
-
# h('<foo>')
|
15
|
-
# end
|
16
|
-
module DeleteHeaders
|
17
|
-
module ResponseMethods
|
18
|
-
def finish
|
19
|
-
res = super
|
20
|
-
res[1].delete_if{|_, v| v.nil?}
|
21
|
-
res
|
22
|
-
end
|
23
|
-
|
24
|
-
def finish_with_body(_)
|
25
|
-
res = super
|
26
|
-
res[1].delete_if{|_, v| v.nil?}
|
27
|
-
res
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
register_plugin(:delete_headers, DeleteHeaders)
|
33
|
-
end
|
34
|
-
end
|
data/spec/module_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
describe "Roda.request_module and .response_module" do
|
4
|
-
it "should include given module in request or response class" do
|
5
|
-
app(:bare) do
|
6
|
-
request_module(Module.new{def h; halt response.finish end})
|
7
|
-
response_module(Module.new{def finish; [1, {}, []] end})
|
8
|
-
|
9
|
-
route do |r|
|
10
|
-
r.h
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
req.should == [1, {}, []]
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should accept blocks and turn them into modules" do
|
18
|
-
app(:bare) do
|
19
|
-
request_module{def h; halt response.finish end}
|
20
|
-
response_module{def finish; [1, {}, []] end}
|
21
|
-
|
22
|
-
route do |r|
|
23
|
-
r.h
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
req.should == [1, {}, []]
|
28
|
-
end
|
29
|
-
end
|