roda 3.54.0 → 3.55.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: '083b83c9271643842b60c7027b16a3ed2068fef54423b3a80dae73ffa991b0cf'
4
- data.tar.gz: c2b9efd6155dd597f13e7167ce6ad6044f8692fb5dafa7994c1527c3a94f1641
3
+ metadata.gz: 1b862c4eb1dcca9fbbf0ccacc130779fdecf610a5a064ef94c17384d073e29dd
4
+ data.tar.gz: 1e9a991190a6572283350bf1941fca8b83f8496bc519156d5ec3cc5d613d2407
5
5
  SHA512:
6
- metadata.gz: e33b2bc1b476bb103d380ac0b310e09640a0bdbce160c7307c92fba93b2dbb2f2a149b2ea3e1db65701354ab274d4d5cea03a7d813f9c81b271bb43d31915503
7
- data.tar.gz: 9c3f7d67ed534f769ba453974b2dca02318a3330064d5f350ed6f8e0d25314513d884cddbaa6a0e0b9fae36b962fec659db050ced37e543201d4271099813eda
6
+ metadata.gz: 55fdc91ab21dbb1cf6884ee6b0384ef15db41f830d704ec6c445435ec76e302cb166f18c6f032390193c6d43d6922c7762d03768fd5c22188c3c7f937dc21d4a
7
+ data.tar.gz: d1272f1fc0e2707d2daf590ea71a4970ae2b133f0b4ba669e60296d6900422d3746bff8722d44eb636df5aefab0bd6b51382b88de1265924c4243322646335e7
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ = 3.55.0 (2022-04-12)
2
+
3
+ * Allow passing blocks to the view method in the render plugin (jeremyevans) (#262)
4
+
5
+ * Add :forward_response_headers middleware plugin option to use app headers as default for response (janko) (#259)
6
+
1
7
  = 3.54.0 (2022-03-14)
2
8
 
3
9
  * Make chunked plugin not use Transfer-Encoding: chunked by default (jeremyevans)
@@ -0,0 +1,12 @@
1
+ = New Features
2
+
3
+ * A :forward_response_headers option has been added to the middleware
4
+ plugin, which uses the response headers added by the middleware
5
+ as default response headers even if the middleware does not handle
6
+ the response. Response headers set by the underlying application
7
+ take precedence over response headers set by the middleware.
8
+
9
+ * The render plugin view method now accepts a block and will pass the
10
+ block to the underlying render method call. This is useful for
11
+ rendering a template that yields inside of an existing layout.
12
+ Previously, you had to nest render calls to do that.
@@ -215,7 +215,7 @@ class Roda
215
215
  # If chunking by default, call chunked if it hasn't yet been
216
216
  # called and chunking is not specifically disabled.
217
217
  def view(*a)
218
- if opts[:chunk_by_default] && !defined?(@_chunked)
218
+ if opts[:chunk_by_default] && !defined?(@_chunked) && !defined?(yield)
219
219
  chunked(*a)
220
220
  else
221
221
  super
@@ -73,11 +73,16 @@ class Roda
73
73
  # and rack response for all requests passing through the middleware,
74
74
  # after either the middleware or next app handles the request
75
75
  # and returns a response.
76
+ # :forward_response_headers :: Whether changes to the response headers made inside
77
+ # the middleware's route block should be applied to the
78
+ # final response when the request is forwarded to the app.
79
+ # Defaults to false.
76
80
  def self.configure(app, opts={}, &block)
77
81
  app.opts[:middleware_env_var] = opts[:env_var] if opts.has_key?(:env_var)
78
82
  app.opts[:middleware_env_var] ||= 'roda.forward_next'
79
83
  app.opts[:middleware_configure] = block if block
80
84
  app.opts[:middleware_handle_result] = opts[:handle_result]
85
+ app.opts[:middleware_forward_response_headers] = opts[:forward_response_headers]
81
86
  end
82
87
 
83
88
  # Forwarder instances are what is actually used as middleware.
@@ -108,6 +113,10 @@ class Roda
108
113
 
109
114
  if call_next
110
115
  res = @app.call(env)
116
+
117
+ if modified_headers = env.delete('roda.response_headers')
118
+ res[1] = modified_headers.merge(res[1])
119
+ end
111
120
  end
112
121
 
113
122
  if handle_result = @mid.opts[:middleware_handle_result]
@@ -135,7 +144,10 @@ class Roda
135
144
  def call(&block)
136
145
  super do |r|
137
146
  res = instance_exec(r, &block) # call Fallback
138
- throw :next, true if r.forward_next
147
+ if r.forward_next
148
+ r.env['roda.response_headers'] = response.headers if opts[:middleware_forward_response_headers]
149
+ throw :next, true
150
+ end
139
151
  res
140
152
  end
141
153
  end
@@ -144,7 +156,10 @@ class Roda
144
156
  # that the next middleware is called.
145
157
  def _roda_run_main_route(r)
146
158
  res = super
147
- throw :next, true if r.forward_next
159
+ if r.forward_next
160
+ r.env['roda.response_headers'] = response.headers if opts[:middleware_forward_response_headers]
161
+ throw :next, true
162
+ end
148
163
  res
149
164
  end
150
165
  end
@@ -495,8 +495,10 @@ class Roda
495
495
 
496
496
  # Render the given template. If there is a default layout
497
497
  # for the class, take the result of the template rendering
498
- # and render it inside the layout. See Render for details.
499
- def view(template, opts = (content = _optimized_view_content(template); OPTS))
498
+ # and render it inside the layout. Blocks passed to view
499
+ # are passed to render when rendering the template.
500
+ # See Render for details.
501
+ def view(template, opts = (content = _optimized_view_content(template) unless defined?(yield); OPTS), &block)
500
502
  if content
501
503
  # First, check if the optimized layout method has already been created,
502
504
  # and use it if so. This way avoids the extra conditional and local variable
@@ -516,7 +518,7 @@ class Roda
516
518
  end
517
519
  else
518
520
  opts = parse_template_opts(template, opts)
519
- content = opts[:content] || render_template(opts)
521
+ content = opts[:content] || render_template(opts, &block)
520
522
  end
521
523
 
522
524
  if layout_opts = view_layout_opts(opts)
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 = 54
7
+ RodaMinorVersion = 55
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
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.54.0
4
+ version: 3.55.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: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: sass
112
+ name: sassc
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -212,6 +212,7 @@ extra_rdoc_files:
212
212
  - doc/release_notes/3.52.0.txt
213
213
  - doc/release_notes/3.53.0.txt
214
214
  - doc/release_notes/3.54.0.txt
215
+ - doc/release_notes/3.55.0.txt
215
216
  - doc/release_notes/3.6.0.txt
216
217
  - doc/release_notes/3.7.0.txt
217
218
  - doc/release_notes/3.8.0.txt
@@ -273,6 +274,7 @@ files:
273
274
  - doc/release_notes/3.52.0.txt
274
275
  - doc/release_notes/3.53.0.txt
275
276
  - doc/release_notes/3.54.0.txt
277
+ - doc/release_notes/3.55.0.txt
276
278
  - doc/release_notes/3.6.0.txt
277
279
  - doc/release_notes/3.7.0.txt
278
280
  - doc/release_notes/3.8.0.txt