roda 2.4.0 → 2.5.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/CHANGELOG +10 -0
- data/doc/release_notes/2.4.0.txt +1 -1
- data/doc/release_notes/2.5.0.txt +23 -0
- data/lib/roda/plugins/assets.rb +10 -3
- data/lib/roda/plugins/multi_run.rb +12 -0
- data/lib/roda/plugins/path.rb +3 -4
- data/lib/roda/plugins/render.rb +18 -2
- data/lib/roda/plugins/websockets.rb +1 -1
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/assets_spec.rb +19 -6
- data/spec/plugin/environments_spec.rb +11 -0
- data/spec/plugin/multi_run_spec.rb +15 -0
- data/spec/plugin/path_spec.rb +9 -0
- data/spec/plugin/render_spec.rb +34 -0
- data/spec/spec_helper.rb +7 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 325e660f0581837d20d346159eea1be6a7363c9c
|
4
|
+
data.tar.gz: eb99e9f1843f9959ae80a7b44900476b749f734f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb3a46ed33cf4086c2d911be08817d60ba7ae522c23ad773824d6938fb6b2ab5bca7c15ce3dfa47a14d6364b37a65b96e29e23fc24b312b8c17d070e39241ac
|
7
|
+
data.tar.gz: 705cbd16aeae28277012f7597f926156b8c825988d167c1cfaf36f2f8c263f6f81c2fe644587dede273cf5e4b9197897eb58a12b6027fadf832198f46b18d083
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
= 2.5.0 (2015-07-14)
|
2
|
+
|
3
|
+
* Make :by_name option to path plugin default to true in development (jeremyevans)
|
4
|
+
|
5
|
+
* Add :cache_class option to render plugin, for customized template cache behavior (celsworth) (#34)
|
6
|
+
|
7
|
+
* Add :compiled_asset_host option to assets plugin, to use a host for compiled assets (jeremyevans)
|
8
|
+
|
9
|
+
* Allow r.multi_run to take a block that is called with the prefix before dispatching to the rack app (mikz) (#32)
|
10
|
+
|
1
11
|
= 2.4.0 (2015-06-15)
|
2
12
|
|
3
13
|
* Add websockets plugin, for integration with faye-websocket (jeremyevans)
|
data/doc/release_notes/2.4.0.txt
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* The assets plugin now supports a :compiled_asset_host option, which
|
4
|
+
specifies a hostname used to serve compiled assets.
|
5
|
+
|
6
|
+
* The render plugin now supports a :cache_class option, which
|
7
|
+
specificies a class to use for the thread-safe template cache.
|
8
|
+
This can be used to setup LRU caching or caching that checks
|
9
|
+
modify times on the underlying template files.
|
10
|
+
|
11
|
+
* r.multi_run in the multi_run plugin now accepts a block, and calls
|
12
|
+
the block before dispatching to the related rack application. This
|
13
|
+
can be used to modify the environment before dispatching. Example:
|
14
|
+
|
15
|
+
r.multi_run do |prefix|
|
16
|
+
env['authenticated'] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
= Backwards Compatibility
|
20
|
+
|
21
|
+
* The :by_name option to the path plugin now defaults to true in
|
22
|
+
development mode. This should only negatively affect applications
|
23
|
+
that register anonymous classes with the path plugin.
|
data/lib/roda/plugins/assets.rb
CHANGED
@@ -189,6 +189,8 @@ class Roda
|
|
189
189
|
#
|
190
190
|
# :add_suffix :: Whether to append a .css or .js extension to asset routes in non-compiled mode
|
191
191
|
# (default: false)
|
192
|
+
# :compiled_asset_host :: The asset host to use for compiled assets. Should include the protocol
|
193
|
+
# as well as the host (e.g. "https://cdn.example.com", "//cdn.example.com")
|
192
194
|
# :compiled_css_dir :: Directory name in which to store the compiled css file,
|
193
195
|
# inside :compiled_path (default: nil)
|
194
196
|
# :compiled_css_route :: Route under :prefix for compiled css assets (default: :compiled_css_dir)
|
@@ -562,14 +564,19 @@ class Roda
|
|
562
564
|
|
563
565
|
# Create a tag for each individual file
|
564
566
|
if compiled = o[:compiled]
|
567
|
+
asset_host = o[:compiled_asset_host]
|
565
568
|
if dirs && !dirs.empty?
|
566
569
|
key = dirs.join(DOT)
|
567
570
|
ckey = "#{stype}.#{key}"
|
568
571
|
if ukey = compiled[ckey]
|
569
|
-
"#{
|
572
|
+
ukey = "#{key}.#{ukey}"
|
570
573
|
end
|
571
|
-
|
572
|
-
|
574
|
+
else
|
575
|
+
ukey = compiled[stype]
|
576
|
+
end
|
577
|
+
|
578
|
+
if ukey
|
579
|
+
"#{tag_start}#{asset_host}#{url_prefix}/#{o[:"compiled_#{stype}_prefix"]}.#{ukey}.#{stype}#{tag_end}"
|
573
580
|
end
|
574
581
|
else
|
575
582
|
asset_dir = o[type]
|
@@ -25,6 +25,17 @@ class Roda
|
|
25
25
|
# starting with +/ro+ to +OtherRodaApp+, and routes starting with +/si+ to
|
26
26
|
# SinatraApp.
|
27
27
|
#
|
28
|
+
# You can pass a block to +multi_run+ that will be called with the prefix,
|
29
|
+
# before dispatching to the rack app:
|
30
|
+
#
|
31
|
+
# App.route do |r|
|
32
|
+
# r.multi_run do |prefix|
|
33
|
+
# # do something based on prefix before the request is passed further
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# This is useful for modifying the environment before passing it to the rack app.
|
38
|
+
#
|
28
39
|
# The multi_run plugin is similar to the multi_route plugin, with the difference
|
29
40
|
# being the multi_route plugin keeps all routing subtrees in the same Roda app/class,
|
30
41
|
# while multi_run dispatches to other rack apps. If you want to isolate your routing
|
@@ -76,6 +87,7 @@ class Roda
|
|
76
87
|
# dispatch the request to the stored rack application.
|
77
88
|
def multi_run
|
78
89
|
on self.class.multi_run_regexp do |prefix|
|
90
|
+
yield prefix if block_given?
|
79
91
|
run scope.class.multi_run_apps[prefix]
|
80
92
|
end
|
81
93
|
end
|
data/lib/roda/plugins/path.rb
CHANGED
@@ -62,12 +62,11 @@ class Roda
|
|
62
62
|
OPTS = {}.freeze
|
63
63
|
|
64
64
|
# Initialize the path classes when loading the plugin. Options:
|
65
|
-
# :by_name :: Register classes by name, which is friendlier when reloading code
|
65
|
+
# :by_name :: Register classes by name, which is friendlier when reloading code (defaults to
|
66
|
+
# true in development mode)
|
66
67
|
def self.configure(app, opts=OPTS)
|
67
68
|
app.instance_eval do
|
68
|
-
|
69
|
-
self.opts[:path_class_by_name] = opts[:by_name]
|
70
|
-
end
|
69
|
+
self.opts[:path_class_by_name] = opts.fetch(:by_name, ENV['RACK_ENV'] == 'development')
|
71
70
|
self.opts[:path_classes] ||= {}
|
72
71
|
unless path_block(String)
|
73
72
|
path(String){|str| str}
|
data/lib/roda/plugins/render.rb
CHANGED
@@ -29,6 +29,7 @@ class Roda
|
|
29
29
|
# :cache :: nil/false to not cache templates (useful for development), defaults
|
30
30
|
# to true unless RACK_ENV is development to automatically use the
|
31
31
|
# default template cache.
|
32
|
+
# :cache_class :: A class to use as the template cache instead of the default.
|
32
33
|
# :engine :: The tilt engine to use for rendering, also the default file extension for
|
33
34
|
# templates, defaults to 'erb'.
|
34
35
|
# :escape :: Use Roda's Erubis escaping support, which makes <tt><%= %></tt> escape output,
|
@@ -132,7 +133,14 @@ class Roda
|
|
132
133
|
opts = app.opts[:render]
|
133
134
|
opts[:engine] = (opts[:engine] || opts[:ext] || "erb").dup.freeze
|
134
135
|
opts[:views] = File.expand_path(opts[:views]||"views", app.opts[:root]).freeze
|
135
|
-
|
136
|
+
|
137
|
+
if opts.fetch(:cache, ENV['RACK_ENV'] != 'development')
|
138
|
+
if cache_class = opts[:cache_class]
|
139
|
+
opts[:cache] = cache_class.new
|
140
|
+
else
|
141
|
+
opts[:cache] = app.thread_safe_cache
|
142
|
+
end
|
143
|
+
end
|
136
144
|
|
137
145
|
opts[:layout_opts] = (opts[:layout_opts] || {}).dup
|
138
146
|
opts[:layout_opts][:_is_layout] = true
|
@@ -182,7 +190,15 @@ class Roda
|
|
182
190
|
def inherited(subclass)
|
183
191
|
super
|
184
192
|
opts = subclass.opts[:render] = subclass.opts[:render].dup
|
185
|
-
|
193
|
+
|
194
|
+
if opts[:cache]
|
195
|
+
if cache_class = opts[:cache_class]
|
196
|
+
opts[:cache] = cache_class.new
|
197
|
+
else
|
198
|
+
opts[:cache] = thread_safe_cache
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
186
202
|
opts.freeze
|
187
203
|
end
|
188
204
|
|
data/lib/roda/version.rb
CHANGED
data/spec/plugin/assets_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
+
run_tests = true
|
4
5
|
begin
|
5
6
|
begin
|
6
|
-
|
7
|
+
require 'tilt/sass'
|
7
8
|
rescue LoadError
|
8
|
-
|
9
|
-
|
9
|
+
begin
|
10
|
+
for lib in %w'tilt sass'
|
11
|
+
require lib
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
warn "#{lib} not installed, skipping assets plugin test"
|
15
|
+
run_tests = false
|
10
16
|
end
|
11
|
-
run_tests = true
|
12
|
-
rescue LoadError
|
13
|
-
warn "#{lib} not installed, skipping assets plugin test"
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
@@ -263,6 +266,16 @@ if run_tests
|
|
263
266
|
js.must_include('console.log')
|
264
267
|
end
|
265
268
|
|
269
|
+
it 'should handle linking to compiled assets when a compiled asset host is used' do
|
270
|
+
app.plugin :assets, :compiled_asset_host=>'https://cdn.example.com'
|
271
|
+
app.compile_assets
|
272
|
+
html = body('/test')
|
273
|
+
html.scan(/<link/).length.must_equal 1
|
274
|
+
html.must_match %r{href="https://cdn\.example\.com/assets/app\.[a-f0-9]{40}\.css"}
|
275
|
+
html.scan(/<script/).length.must_equal 1
|
276
|
+
html.must_match %r{src="https://cdn\.example\.com/assets/app\.head\.[a-f0-9]{40}\.js"}
|
277
|
+
end
|
278
|
+
|
266
279
|
it 'should handle compiling assets, linking to them, and accepting requests for them when :gzip is set' do
|
267
280
|
app.plugin :assets, :gzip=>true
|
268
281
|
app.compile_assets
|
@@ -28,4 +28,15 @@ describe "environments plugin" do
|
|
28
28
|
app.configure(:test, :production){a << 2}
|
29
29
|
a.must_equal [1, app]
|
30
30
|
end
|
31
|
+
|
32
|
+
it "defaults environment to RACK_ENV" do
|
33
|
+
with_rack_env('test') do
|
34
|
+
app(:environments){}
|
35
|
+
end
|
36
|
+
app.test?.must_equal true
|
37
|
+
app.development?.must_equal false
|
38
|
+
app(:environments){}
|
39
|
+
app.test?.must_equal false
|
40
|
+
app.development?.must_equal true
|
41
|
+
end
|
31
42
|
end
|
@@ -69,4 +69,19 @@ describe "multi_run plugin" do
|
|
69
69
|
@app = a
|
70
70
|
body("/b").must_equal 'b2'
|
71
71
|
end
|
72
|
+
|
73
|
+
it "yields prefix" do
|
74
|
+
yielded = false
|
75
|
+
|
76
|
+
app(:multi_run) do |r|
|
77
|
+
r.multi_run do |prefix|
|
78
|
+
yielded = prefix
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
app.run "a", Class.new(Roda).class_eval{route{"a1"}; app}
|
83
|
+
|
84
|
+
body("/a").must_equal "a1"
|
85
|
+
yielded.must_equal "a"
|
86
|
+
end
|
72
87
|
end
|
data/spec/plugin/path_spec.rb
CHANGED
@@ -188,6 +188,15 @@ describe "path plugin" do
|
|
188
188
|
body('c'=>c2.new).must_equal '/c'
|
189
189
|
end
|
190
190
|
|
191
|
+
it ":by_name defaults to true in development" do
|
192
|
+
with_rack_env('development') do
|
193
|
+
app(:path){}
|
194
|
+
end
|
195
|
+
app.opts[:path_class_by_name].must_equal true
|
196
|
+
app(:path){}
|
197
|
+
app.opts[:path_class_by_name].must_equal false
|
198
|
+
end
|
199
|
+
|
191
200
|
it "Roda.path_block returns the block used" do
|
192
201
|
c = Class.new
|
193
202
|
b = proc{|x| x.to_s}
|
data/spec/plugin/render_spec.rb
CHANGED
@@ -324,6 +324,15 @@ describe "render plugin" do
|
|
324
324
|
body('/c').must_equal "3"
|
325
325
|
end
|
326
326
|
|
327
|
+
it "Default to :cache=>false in development mode" do
|
328
|
+
with_rack_env('development') do
|
329
|
+
app(:render){}
|
330
|
+
end
|
331
|
+
app.render_opts[:cache].must_equal nil
|
332
|
+
app(:render){}
|
333
|
+
app.render_opts[:cache].wont_equal nil
|
334
|
+
end
|
335
|
+
|
327
336
|
it "Support :cache=>false option to disable template caching" do
|
328
337
|
app(:bare) do
|
329
338
|
plugin :render, :views=>"./spec/views"
|
@@ -416,5 +425,30 @@ describe "render plugin" do
|
|
416
425
|
|
417
426
|
Class.new(app).render_opts[:cache].must_equal false
|
418
427
|
end
|
428
|
+
it "with a cache_class set" do
|
429
|
+
app(:bare) do
|
430
|
+
test_cache = Class.new(Roda::RodaCache) do
|
431
|
+
def [](key)
|
432
|
+
super
|
433
|
+
end
|
434
|
+
def []=(key, value)
|
435
|
+
super
|
436
|
+
end
|
437
|
+
def test_method
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
plugin :render, :views=>"./spec/views", :cache=>true, :cache_class=>test_cache
|
442
|
+
|
443
|
+
route do |r|
|
444
|
+
view(:inline=>"foo", :layout=>nil)
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
body("/inline").strip.must_equal "foo"
|
449
|
+
|
450
|
+
Class.new(app).render_opts[:cache].must_respond_to :test_method
|
451
|
+
end
|
452
|
+
|
419
453
|
end
|
420
454
|
end
|
data/spec/spec_helper.rb
CHANGED
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.5.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-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -141,6 +141,7 @@ extra_rdoc_files:
|
|
141
141
|
- doc/release_notes/2.2.0.txt
|
142
142
|
- doc/release_notes/2.3.0.txt
|
143
143
|
- doc/release_notes/2.4.0.txt
|
144
|
+
- doc/release_notes/2.5.0.txt
|
144
145
|
files:
|
145
146
|
- CHANGELOG
|
146
147
|
- MIT-LICENSE
|
@@ -156,6 +157,7 @@ files:
|
|
156
157
|
- doc/release_notes/2.2.0.txt
|
157
158
|
- doc/release_notes/2.3.0.txt
|
158
159
|
- doc/release_notes/2.4.0.txt
|
160
|
+
- doc/release_notes/2.5.0.txt
|
159
161
|
- lib/roda.rb
|
160
162
|
- lib/roda/plugins/_erubis_escaping.rb
|
161
163
|
- lib/roda/plugins/all_verbs.rb
|