roda 3.4.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc5d44e8586188ebb590d75d204b22fdd5b547c35e8631d31cf184ef5bfc0908
4
- data.tar.gz: 03f023b11296d7cdebe72229d47988f3cf644ef3e80f243030e3b678c0ee9cb3
3
+ metadata.gz: 6f0422791db9ddee07b535f5429fd17ae5f312c7e5c7519dfbe0288e1d285919
4
+ data.tar.gz: 905f19053a3997fc7c3c4e4b942b73cd2400cb59df641cb4a86b23191cab873c
5
5
  SHA512:
6
- metadata.gz: 942fb33ceeb0faef69467fa5b705bfd8b73f92bfb27557f58c9d459a9c1f1d4447eec1ac10c5cbf4eacf09293f20a4562e997125a41a226c5fb673154b85524d
7
- data.tar.gz: e5d5f9533bed9c0c126a1203a9715bda8461b587bfb647a70a8aae1dd0a951cb5512d189c2e205ccbc1d67086afaa4e2a8c7104c741824c0ab3f8003fe999a98
6
+ metadata.gz: 10aff2c1df661f7cb2699cb3f49bf521587813017ca5cc5c1117c629f04805075e185170305cc012cbbdc2c4ecae59902f73efab1ff39806d3f9548acc918d8b
7
+ data.tar.gz: d6b70c570f4e198b743ecb4f216f600ad09b8010d6e1df1c202873b843846d1fac3c817dfd848fc7509efc4ba8f41d5907c4273187871ab8293810dc307018e5
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ = 3.5.0 (2018-02-14)
2
+
3
+ * Add request_aref plugin for configuring behavior of request [] and []= methods (jeremyevans)
4
+
5
+ * Make public plugin not add Content-Type header when serving 304 response for gzipped file (jeremyevans)
6
+
7
+ * Make content_for call with block convert block result to string before passing to tilt (jeremyevans) (#135)
8
+
1
9
  = 3.4.0 (2018-01-12)
2
10
 
3
11
  * Add middleware_stack plugin for removing middleware and inserting middleware before the end of the stack (jeremyevans)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2017 Jeremy Evans
1
+ Copyright (c) 2014-2018 Jeremy Evans
2
2
  Copyright (c) 2010-2014 Michel Martens, Damian Janowski and Cyril David
3
3
  Copyright (c) 2008-2009 Christian Neukirchen
4
4
 
data/README.rdoc CHANGED
@@ -274,7 +274,7 @@ The +/+ here is considered the empty segment.
274
274
 
275
275
  === String
276
276
 
277
- If a string does not contain a colon or slash, it matches a single segment
277
+ If a string does not contain a slash, it matches a single segment
278
278
  containing the text of the string, preceded by a slash.
279
279
 
280
280
  "" # matches "/"
@@ -0,0 +1,31 @@
1
+ = New Features
2
+
3
+ * A request_aref plugin has been added for configuring the behavior
4
+ of the [] and []= request methods. These methods are deprecated
5
+ in the current version of Rack, but Rack will only print a
6
+ deprecation warning in verbose mode. With this plugin, you can
7
+ choose to never warn, always warn, or raise an exception:
8
+
9
+ # Don't emit a warning, allowing for the historical Rack
10
+ # behavior
11
+ plugin :request_aref, :allow
12
+
13
+ # Always emit a warning when the method is called
14
+ plugin :request_aref, :warn
15
+
16
+ # Raise an exception if the method is called
17
+ plugin :request_aref, :raise
18
+
19
+ = Other Improvements
20
+
21
+ * When using the content_for plugin and calling content_for with a
22
+ block, convert the result of the block to a string before passing
23
+ the result to Tilt. This can fix issues when the template class
24
+ that Tilt uses does not handle non-String input.
25
+
26
+ * When using the public plugin with the :gzip option, do not add the
27
+ Content-Type or Content-Encoding headers if a 304 response is
28
+ returned.
29
+
30
+ * Add the spec/views/about directory to the gem, allowing the specs
31
+ to run correctly using just the files in the gem.
@@ -52,17 +52,17 @@ class Roda
52
52
  # under the given key. If called without a block, retrieve
53
53
  # stored content with the given key, or return nil if there
54
54
  # is no content stored with that key.
55
- def content_for(key, value=nil, &block)
55
+ def content_for(key, value=nil)
56
56
  append = opts[:append_content_for]
57
57
 
58
- if block || value
59
- if block
58
+ if block_given? || value
59
+ if block_given?
60
60
  outvar = render_opts[:template_opts][:outvar]
61
61
  buf_was = instance_variable_get(outvar)
62
62
 
63
63
  # Use temporary output buffer for ERB-based rendering systems
64
64
  instance_variable_set(outvar, String.new)
65
- value = Tilt[render_opts[:engine]].new(&block).render
65
+ value = Tilt[render_opts[:engine]].new{yield.to_s}.render
66
66
  instance_variable_set(outvar, buf_was)
67
67
  end
68
68
 
@@ -72,10 +72,12 @@ class Roda
72
72
  res = public_serve(server, gzip_path)
73
73
  headers = res[1]
74
74
 
75
- if mime_type = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain')
76
- headers['Content-Type'] = mime_type
75
+ unless res[0] == 304
76
+ if mime_type = ::Rack::Mime.mime_type(::File.extname(path), 'text/plain')
77
+ headers['Content-Type'] = mime_type
78
+ end
79
+ headers['Content-Encoding'] = 'gzip'
77
80
  end
78
- headers['Content-Encoding'] = 'gzip'
79
81
 
80
82
  halt res
81
83
  end
@@ -0,0 +1,77 @@
1
+ # frozen-string-literal: true
2
+
3
+ #
4
+ class Roda
5
+ module RodaPlugins
6
+ # The request_aref plugin allows for custom handling of the r[] and r[]=
7
+ # methods (where r is the Request instance). In the current version of
8
+ # rack, these methods are deprecated, but the deprecation message is only
9
+ # printed in verbose mode. This plugin can allow for handling calls to
10
+ # these methods in one of three ways:
11
+ #
12
+ # :allow :: Allow the method calls without a deprecation, which is the
13
+ # historical behavior
14
+ # :warn :: Always issue a deprecation message by calling +warn+, not just
15
+ # in verbose mode.
16
+ # :raise :: Raise an error if either method is called
17
+ module RequestAref
18
+ # Make #[] and #[]= methods work as configured by aliasing the appropriate
19
+ # request_a(ref|set)_* methods to them.
20
+ def self.configure(app, setting)
21
+ case setting
22
+ when :allow, :raise, :warn
23
+ app::RodaRequest.class_eval do
24
+ alias_method(:[], :"request_aref_#{setting}")
25
+ alias_method(:[]=, :"request_aset_#{setting}")
26
+ public :[], :[]=
27
+ end
28
+ else
29
+ raise RodaError, "Unsupport request_aref plugin setting: #{setting.inspect}"
30
+ end
31
+ end
32
+
33
+ # Exception class raised when #[] or #[]= are called when the
34
+ # :raise setting is used.
35
+ class Error < RodaError
36
+ end
37
+
38
+ module RequestMethods
39
+ private
40
+
41
+ # Allow #[] calls
42
+ def request_aref_allow(k)
43
+ params[k.to_s]
44
+ end
45
+
46
+ # Always warn on #[] calls
47
+ def request_aref_warn(k)
48
+ warn("#{self.class}#[] is deprecated, use #params.[] instead")
49
+ params[k.to_s]
50
+ end
51
+
52
+ # Raise error on #[] calls
53
+ def request_aref_raise(k)
54
+ raise Error, "#{self.class}#[] has been removed, use #params.[] instead"
55
+ end
56
+
57
+ # Allow #[]= calls
58
+ def request_aset_allow(k, v)
59
+ params[k.to_s] = v
60
+ end
61
+
62
+ # Always warn on #[]= calls
63
+ def request_aset_warn(k, v)
64
+ warn("#{self.class}#[]= is deprecated, use #params.[]= instead")
65
+ params[k.to_s] = v
66
+ end
67
+
68
+ # Raise error on #[]= calls
69
+ def request_aset_raise(k, v)
70
+ raise Error, "#{self.class}#[]= has been removed, use #params.[]= instead"
71
+ end
72
+ end
73
+ end
74
+
75
+ register_plugin(:request_aref, RequestAref)
76
+ end
77
+ end
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
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.
data/lib/roda.rb CHANGED
@@ -722,9 +722,9 @@ class Roda
722
722
  consume(self.class.cached_matcher(re){re})
723
723
  end
724
724
 
725
- # Match the given string to the request path. Regexp escapes the
726
- # string so that regexp metacharacters are not matched, and recognizes
727
- # colon tokens for placeholders.
725
+ # Match the given string to the request path. Matches only if the
726
+ # request path ends with the string or if the next character in the
727
+ # request path is a slash (indicating a new segment).
728
728
  def _match_string(str)
729
729
  rp = @remaining_path
730
730
  if rp.start_with?("/#{str}")
@@ -21,6 +21,9 @@ describe "content_for plugin with erb" do
21
21
  r.get 'b' do
22
22
  view(:inline => '<% content_for(:foo, "foo") %>bar', :layout => { :inline => '<%= yield %> <%= content_for(:foo) %>' })
23
23
  end
24
+ r.get 'e' do
25
+ view(:inline => 'a<% content_for :foo do %><% end %>b', :layout => { :inline => 'c<%= yield %>d<%= content_for(:foo) %>e' })
26
+ end
24
27
  end
25
28
  end
26
29
  end
@@ -36,6 +39,10 @@ describe "content_for plugin with erb" do
36
39
  it "should work if a raw string is set" do
37
40
  body('/b').strip.must_equal "bar foo"
38
41
  end
42
+
43
+ it "should work for an empty content_for" do
44
+ body('/e').strip.must_equal "cabde"
45
+ end
39
46
  end
40
47
 
41
48
  describe "content_for plugin with multiple calls to the same key" do
@@ -75,5 +75,11 @@ describe "public plugin" do
75
75
  h = req('/about/_test.css', 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')[1]
76
76
  h['Content-Encoding'].must_equal 'gzip'
77
77
  h['Content-Type'].must_equal 'text/css'
78
+
79
+ s, h, b = req('/about/_test.css', 'HTTP_IF_MODIFIED_SINCE'=>h["Last-Modified"], 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')
80
+ s.must_equal 304
81
+ h['Content-Encoding'].must_be_nil
82
+ h['Content-Type'].must_be_nil
83
+ b.must_equal []
78
84
  end
79
85
  end
@@ -0,0 +1,51 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe "request_aref plugin" do
4
+ def request_aref_app(value)
5
+ warning = @warning = String.new('')
6
+ app(:bare) do
7
+ plugin :request_aref, value
8
+ self::RodaRequest.send(:define_method, :warn){|s| warning.replace(s)}
9
+ route do |r|
10
+ r.get('set'){r['b'] = 'c'; r.params['b']}
11
+ r['a']
12
+ end
13
+ end
14
+ end
15
+
16
+ def aref_body
17
+ body("QUERY_STRING" => 'a=d', 'rack.input'=>StringIO.new)
18
+ end
19
+
20
+ def aset_body
21
+ body('/set', "QUERY_STRING" => 'a=d', 'rack.input'=>StringIO.new)
22
+ end
23
+
24
+ it "allows if given the :allow option" do
25
+ request_aref_app(:allow)
26
+ aref_body.must_equal 'd'
27
+ @warning.must_equal ''
28
+ aset_body.must_equal 'c'
29
+ @warning.must_equal ''
30
+ end
31
+
32
+ it "warns if given the :warn option" do
33
+ request_aref_app(:warn)
34
+ aref_body.must_equal 'd'
35
+ @warning.must_include('#[] is deprecated, use #params.[] instead')
36
+ aset_body.must_equal 'c'
37
+ @warning.must_include('#[]= is deprecated, use #params.[]= instead')
38
+ end
39
+
40
+ it "raises if given the :raise option" do
41
+ request_aref_app(:raise)
42
+ proc{aref_body}.must_raise Roda::RodaPlugins::RequestAref::Error
43
+ @warning.must_equal ''
44
+ proc{aset_body}.must_raise Roda::RodaPlugins::RequestAref::Error
45
+ @warning.must_equal ''
46
+ end
47
+
48
+ it "raises when loading plugin if given other option" do
49
+ proc{request_aref_app(:r)}.must_raise Roda::RodaError
50
+ end
51
+ end
Binary file
@@ -0,0 +1 @@
1
+ <h1>Subdir: <%= title %></h1>
Binary file
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: 3.4.0
4
+ version: 3.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: 2018-01-12 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -200,6 +200,7 @@ extra_rdoc_files:
200
200
  - doc/release_notes/3.2.0.txt
201
201
  - doc/release_notes/3.3.0.txt
202
202
  - doc/release_notes/3.4.0.txt
203
+ - doc/release_notes/3.5.0.txt
203
204
  files:
204
205
  - CHANGELOG
205
206
  - MIT-LICENSE
@@ -246,6 +247,7 @@ files:
246
247
  - doc/release_notes/3.2.0.txt
247
248
  - doc/release_notes/3.3.0.txt
248
249
  - doc/release_notes/3.4.0.txt
250
+ - doc/release_notes/3.5.0.txt
249
251
  - lib/roda.rb
250
252
  - lib/roda/plugins/_symbol_regexp_matchers.rb
251
253
  - lib/roda/plugins/all_verbs.rb
@@ -309,6 +311,7 @@ files:
309
311
  - lib/roda/plugins/render.rb
310
312
  - lib/roda/plugins/render_each.rb
311
313
  - lib/roda/plugins/render_locals.rb
314
+ - lib/roda/plugins/request_aref.rb
312
315
  - lib/roda/plugins/request_headers.rb
313
316
  - lib/roda/plugins/response_request.rb
314
317
  - lib/roda/plugins/run_append_slash.rb
@@ -403,6 +406,7 @@ files:
403
406
  - spec/plugin/render_each_spec.rb
404
407
  - spec/plugin/render_locals_spec.rb
405
408
  - spec/plugin/render_spec.rb
409
+ - spec/plugin/request_aref_spec.rb
406
410
  - spec/plugin/request_headers_spec.rb
407
411
  - spec/plugin/response_request_spec.rb
408
412
  - spec/plugin/run_append_slash_spec.rb
@@ -435,6 +439,9 @@ files:
435
439
  - spec/views/a.erb
436
440
  - spec/views/about.erb
437
441
  - spec/views/about.str
442
+ - spec/views/about/_test.css.gz
443
+ - spec/views/about/_test.erb
444
+ - spec/views/about/_test.erb.gz
438
445
  - spec/views/b.erb
439
446
  - spec/views/c.erb
440
447
  - spec/views/content-yield.erb