roda 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4196dbdea5add49bdf94cb6c59d5f10f3d2d6464
4
- data.tar.gz: 23b683d38973ae9c47d99033e35f71be7ae89e68
3
+ metadata.gz: 325e660f0581837d20d346159eea1be6a7363c9c
4
+ data.tar.gz: eb99e9f1843f9959ae80a7b44900476b749f734f
5
5
  SHA512:
6
- metadata.gz: 79a29e4ad2df5b81307e3db2bd768c10937f9a704f93d5702b97779ee1f6821b223e60b5011ce3c482220bf56d993d3aa67473e1bd6a8b68869135123ee29897
7
- data.tar.gz: 7ffc00c161bf098279cf9b5e61bd02aa5e99531e9c4bd1072ab7b97a191ff77e1c417a037e8f1c7b2d8d2dc757fc15d667d57d622aa001a3e568c467700ce8be
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)
@@ -4,7 +4,7 @@
4
4
  faye-websocket. Here's an example of a simple echo service using
5
5
  websockets:
6
6
 
7
- plugin :websocket
7
+ plugin :websockets
8
8
 
9
9
  route do |r|
10
10
  r.get "echo" do
@@ -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.
@@ -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
- "#{tag_start}#{url_prefix}/#{o[:"compiled_#{stype}_prefix"]}.#{key}.#{ukey}.#{stype}#{tag_end}"
572
+ ukey = "#{key}.#{ukey}"
570
573
  end
571
- elsif ukey = compiled[stype]
572
- "#{tag_start}#{url_prefix}/#{o[:"compiled_#{stype}_prefix"]}.#{ukey}.#{stype}#{tag_end}"
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
@@ -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
- if opts.has_key?(:by_name)
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}
@@ -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
- opts[:cache] = app.thread_safe_cache if opts.fetch(:cache, ENV['RACK_ENV'] != 'development')
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
- opts[:cache] = thread_safe_cache if opts[:cache]
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
 
@@ -15,7 +15,7 @@ class Roda
15
15
  # is sent to all other users in the same room, using a websocket
16
16
  # per room:
17
17
  #
18
- # plugin :websockets, :adapter=>:thin, :opts=>{:ping=>45}
18
+ # plugin :websockets, :adapter=>:thin, :ping=>45
19
19
  #
20
20
  # MUTEX = Mutex.new
21
21
  # ROOMS = {}
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 2
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 4
7
+ RodaMinorVersion = 5
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
@@ -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
- require 'tilt/sass'
7
+ require 'tilt/sass'
7
8
  rescue LoadError
8
- for lib in %w'tilt sass'
9
- require lib
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
@@ -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}
@@ -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
@@ -75,4 +75,11 @@ class Minitest::Spec
75
75
  c.class_eval(&block)
76
76
  c
77
77
  end
78
+
79
+ def with_rack_env(env)
80
+ ENV['RACK_ENV'] = env
81
+ yield
82
+ ensure
83
+ ENV.delete('RACK_ENV')
84
+ end
78
85
  end
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.0
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-06-15 00:00:00.000000000 Z
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