roda 3.14.1 → 3.15.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 +6 -0
- data/doc/release_notes/3.15.0.txt +21 -0
- data/lib/roda/plugins/render.rb +19 -7
- data/lib/roda/plugins/typecast_params.rb +13 -3
- data/lib/roda/version.rb +2 -2
- data/spec/plugin/render_spec.rb +38 -2
- data/spec/plugin/typecast_params_spec.rb +38 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a3a695566853202815ee8857b9f2276b06d97204c98b06985d2a78c1a535dab
|
4
|
+
data.tar.gz: 700b5fbd7c73c2ed9a3f758ddae5476f1428659a39142ab2ce6b155c1cab197d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc207cd02ca21544f435e6a6d22420915087c1418ede8fe5a5468267e1df070354199c5d13b41a41c7900a20608b7ce020bb1af8bdcb495a2751b34a3826254b
|
7
|
+
data.tar.gz: 2685a3c79454feb84de1c58137f8488f82f8b17f89f9f61973bd62ed0ce62ea460f91d871b4b80b83dca21ecb0e0cc073d6a54a148f098e845e8250f92d583cf
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 3.15.0 (2018-12-14)
|
2
|
+
|
3
|
+
* Support render plugin :escape option to be a string or array of strings and only add :escape option for those template engines (jeremyevans) (#158)
|
4
|
+
|
5
|
+
* Add :skip_missing option to convert!/convert_each! in the typecast_params plugin to support not storing keys not present in params (jeremyevans)
|
6
|
+
|
1
7
|
= 3.14.1 (2018-11-29)
|
2
8
|
|
3
9
|
* SECURITY: content_for plugin no longer post-processes block result with template engine (jeremyevans)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* The render plugin :escape option value can now be a string or an
|
4
|
+
array of strings, and then the plugin will will only add the
|
5
|
+
:escape template option for those specific template engines given.
|
6
|
+
By default, the :escape plugin option adds the :escape template
|
7
|
+
option for all engines, which breaks the usage with some engines
|
8
|
+
(such as the rcsv engine).
|
9
|
+
|
10
|
+
* The convert! and convert_each! methods in the typecast_params plugin
|
11
|
+
now support a :skip_missing option to support not storing missing
|
12
|
+
parameters:
|
13
|
+
|
14
|
+
typecast_params.convert! do |tp|
|
15
|
+
tp.int('missing')
|
16
|
+
end
|
17
|
+
# => {'missing'=>nil}
|
18
|
+
typecast_params.convert!(skip_missing: false) do |tp|
|
19
|
+
tp.int('missing')
|
20
|
+
end
|
21
|
+
# => {}
|
data/lib/roda/plugins/render.rb
CHANGED
@@ -56,6 +56,10 @@ class Roda
|
|
56
56
|
# templates, defaults to 'erb'.
|
57
57
|
# :escape :: Use Erubi as the ERB template engine, and enable escaping by default,
|
58
58
|
# which makes <tt><%= %></tt> escape output and <tt><%== %></tt> not escape output.
|
59
|
+
# If given, sets the <tt>:escape=>true</tt> option for all template engines, which
|
60
|
+
# can break some non-ERB template engines. You can use a string or array of strings
|
61
|
+
# as the value for this option to only set the <tt>:escape=>true</tt> option for those
|
62
|
+
# specific template engines.
|
59
63
|
# :layout :: The base name of the layout file, defaults to 'layout'. This can be provided as a hash
|
60
64
|
# with the :template or :inline options.
|
61
65
|
# :layout_opts :: The options to use when rendering the layout, if different from the default options.
|
@@ -184,18 +188,26 @@ class Roda
|
|
184
188
|
template_opts[:default_encoding] = Encoding.default_external
|
185
189
|
end
|
186
190
|
|
187
|
-
if opts[:escape]
|
188
|
-
require 'tilt/erubi'
|
189
|
-
template_opts[:escape] = true
|
190
|
-
end
|
191
|
-
template_opts.freeze
|
192
|
-
|
193
191
|
engine_opts = opts[:engine_opts] = (opts[:engine_opts] || {}).dup
|
194
192
|
engine_opts.to_a.each do |k,v|
|
195
193
|
engine_opts[k] = v.dup.freeze
|
196
194
|
end
|
197
|
-
engine_opts.freeze
|
198
195
|
|
196
|
+
if escape = opts[:escape]
|
197
|
+
require 'tilt/erubi'
|
198
|
+
|
199
|
+
case escape
|
200
|
+
when String, Array
|
201
|
+
Array(escape).each do |engine|
|
202
|
+
engine_opts[engine] = (engine_opts[engine] || {}).merge(:escape => true).freeze
|
203
|
+
end
|
204
|
+
else
|
205
|
+
template_opts[:escape] = true
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
template_opts.freeze
|
210
|
+
engine_opts.freeze
|
199
211
|
opts.freeze
|
200
212
|
end
|
201
213
|
|
@@ -557,7 +557,7 @@ class Roda
|
|
557
557
|
end
|
558
558
|
|
559
559
|
@subs[key] = sub
|
560
|
-
sub.sub_capture(@capture, @symbolize)
|
560
|
+
sub.sub_capture(@capture, @symbolize, @skip_missing)
|
561
561
|
sub
|
562
562
|
end
|
563
563
|
|
@@ -573,6 +573,8 @@ class Roda
|
|
573
573
|
# the options hash. Options:
|
574
574
|
#
|
575
575
|
# :raise :: If set to false, do not raise errors for missing keys
|
576
|
+
# :skip_missing :: If set to true, does not store values if the key is not
|
577
|
+
# present in the params.
|
576
578
|
# :symbolize :: Convert any string keys in the resulting hash and for any
|
577
579
|
# conversions below
|
578
580
|
def convert!(keys=nil, opts=OPTS)
|
@@ -748,9 +750,10 @@ class Roda
|
|
748
750
|
end
|
749
751
|
|
750
752
|
# Inherit given capturing and symbolize setting from parent object.
|
751
|
-
def sub_capture(capture, symbolize)
|
753
|
+
def sub_capture(capture, symbolize, skip_missing)
|
752
754
|
if @capture = capture
|
753
755
|
@symbolize = symbolize
|
756
|
+
@skip_missing = skip_missing
|
754
757
|
@params = @obj.class.new
|
755
758
|
end
|
756
759
|
end
|
@@ -766,6 +769,7 @@ class Roda
|
|
766
769
|
# Internals of convert! and convert_each!.
|
767
770
|
def _capture!(ret, opts)
|
768
771
|
previous_symbolize = @symbolize
|
772
|
+
previous_skip_missing = @skip_missing
|
769
773
|
|
770
774
|
unless cap = @capture
|
771
775
|
@params = @obj.class.new
|
@@ -777,6 +781,9 @@ class Roda
|
|
777
781
|
if opts.has_key?(:symbolize)
|
778
782
|
@symbolize = !!opts[:symbolize]
|
779
783
|
end
|
784
|
+
if opts.has_key?(:skip_missing)
|
785
|
+
@skip_missing = !!opts[:skip_missing]
|
786
|
+
end
|
780
787
|
|
781
788
|
begin
|
782
789
|
v = yield
|
@@ -810,6 +817,7 @@ class Roda
|
|
810
817
|
end
|
811
818
|
|
812
819
|
@symbolize = previous_symbolize
|
820
|
+
@skip_missing = previous_skip_missing
|
813
821
|
end
|
814
822
|
|
815
823
|
# Raise an error if the array given does contains nil values.
|
@@ -906,7 +914,9 @@ class Roda
|
|
906
914
|
|
907
915
|
if @capture
|
908
916
|
key = key.to_sym if symbolize?
|
909
|
-
@
|
917
|
+
if !@skip_missing || @obj.has_key?(key)
|
918
|
+
@params[key] = v
|
919
|
+
end
|
910
920
|
end
|
911
921
|
|
912
922
|
v
|
data/lib/roda/version.rb
CHANGED
@@ -4,11 +4,11 @@ class Roda
|
|
4
4
|
RodaMajorVersion = 3
|
5
5
|
|
6
6
|
# The minor version of Roda, updated for new feature releases of Roda.
|
7
|
-
RodaMinorVersion =
|
7
|
+
RodaMinorVersion = 15
|
8
8
|
|
9
9
|
# The patch version of Roda, updated only for bug fixes from the last
|
10
10
|
# feature release.
|
11
|
-
RodaPatchVersion =
|
11
|
+
RodaPatchVersion = 0
|
12
12
|
|
13
13
|
# The full version of Roda as a string.
|
14
14
|
RodaVersion = "#{RodaMajorVersion}.#{RodaMinorVersion}.#{RodaPatchVersion}".freeze
|
data/spec/plugin/render_spec.rb
CHANGED
@@ -632,7 +632,7 @@ describe ":render plugin :escape option" do
|
|
632
632
|
|
633
633
|
it "should escape inside <%= %> and not inside <%== %>, and handle postfix conditionals" do
|
634
634
|
app(:bare) do
|
635
|
-
plugin :render, :escape
|
635
|
+
plugin :render, :escape=>true
|
636
636
|
|
637
637
|
route do |r|
|
638
638
|
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
|
@@ -644,7 +644,7 @@ describe ":render plugin :escape option" do
|
|
644
644
|
|
645
645
|
it "should allow for per-branch escaping via set_view options" do
|
646
646
|
app(:bare) do
|
647
|
-
plugin :render, :escape
|
647
|
+
plugin :render, :escape=>true
|
648
648
|
plugin :view_options
|
649
649
|
|
650
650
|
route do |r|
|
@@ -660,5 +660,41 @@ describe ":render plugin :escape option" do
|
|
660
660
|
body('/a').must_equal '<>'
|
661
661
|
body.must_equal '<>'
|
662
662
|
end
|
663
|
+
|
664
|
+
it "should accept :escape=>String to only escape for that template engine" do
|
665
|
+
app(:bare) do
|
666
|
+
plugin :render, :escape=>'erb'
|
667
|
+
|
668
|
+
route do |r|
|
669
|
+
r.is 'a' do
|
670
|
+
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>', :engine=>'unescaped.erb')
|
671
|
+
end
|
672
|
+
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
body.must_equal '<> <>'
|
677
|
+
body('/a').must_equal '<> <>'
|
678
|
+
end
|
679
|
+
|
680
|
+
it "should accept :escape=>Array to only escape for those template engines" do
|
681
|
+
app(:bare) do
|
682
|
+
plugin :render, :escape=>%w'erb erubi', :engine_opts=>{'erubi'=>{:bufvar=>'_buf'}}
|
683
|
+
|
684
|
+
route do |r|
|
685
|
+
r.is 'a' do
|
686
|
+
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>', :engine=>'unescaped.erb')
|
687
|
+
end
|
688
|
+
r.is 'b' do
|
689
|
+
render(:inline=>'<%= _buf.length %><%= "<>" %> <%== "<>" %><%= "<>" if false %>', :engine=>'erubi')
|
690
|
+
end
|
691
|
+
render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
|
692
|
+
end
|
693
|
+
end
|
694
|
+
|
695
|
+
body.must_equal '<> <>'
|
696
|
+
body('/a').must_equal '<> <>'
|
697
|
+
body('/b').must_equal '0<> <>'
|
698
|
+
end
|
663
699
|
end
|
664
700
|
end
|
@@ -616,6 +616,44 @@ describe "typecast_params plugin" do
|
|
616
616
|
end.must_equal(:a=>{:b=>1}, :c=>{:d=>2})
|
617
617
|
end
|
618
618
|
|
619
|
+
it "#convert! should include missing values as nil" do
|
620
|
+
tp = tp()
|
621
|
+
tp.convert! do |ptp|
|
622
|
+
ptp.int('x')
|
623
|
+
ptp.array(:int, 'y')
|
624
|
+
ptp['c'].convert! do |stp|
|
625
|
+
stp.int(%w'x z')
|
626
|
+
end
|
627
|
+
end.must_equal("x"=>nil, "y"=>nil, "c"=>{"x"=>nil, "z"=>nil})
|
628
|
+
end
|
629
|
+
|
630
|
+
it "#convert! with :missing=>:skip should not include missing values" do
|
631
|
+
tp = tp()
|
632
|
+
tp.convert!(:skip_missing=>true) do |ptp|
|
633
|
+
ptp.int('x')
|
634
|
+
ptp.array(:int, 'y')
|
635
|
+
ptp['c'].convert! do |stp|
|
636
|
+
stp.int(%w'x z')
|
637
|
+
end
|
638
|
+
end.must_equal("c"=>{})
|
639
|
+
|
640
|
+
tp.convert! do |ptp|
|
641
|
+
ptp.int('x')
|
642
|
+
ptp.array(:int, 'y')
|
643
|
+
ptp['c'].convert!(:skip_missing=>true) do |stp|
|
644
|
+
stp.int(%w'x z')
|
645
|
+
end
|
646
|
+
end.must_equal("x"=>nil, "y"=>nil, "c"=>{})
|
647
|
+
|
648
|
+
tp.convert!(:skip_missing=>true) do |ptp|
|
649
|
+
ptp.int('x')
|
650
|
+
ptp.array(:int, 'y')
|
651
|
+
ptp['c'].convert!(:skip_missing=>false) do |stp|
|
652
|
+
stp.int(%w'x z')
|
653
|
+
end
|
654
|
+
end.must_equal("c"=>{"x"=>nil, "z"=>nil})
|
655
|
+
end
|
656
|
+
|
619
657
|
it "#convert_each! should convert each entry in an array" do
|
620
658
|
tp = tp('a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4')
|
621
659
|
tp['a'].convert_each! do |tp0|
|
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
|
+
version: 3.15.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-
|
11
|
+
date: 2018-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -211,6 +211,7 @@ extra_rdoc_files:
|
|
211
211
|
- doc/release_notes/3.13.0.txt
|
212
212
|
- doc/release_notes/3.14.0.txt
|
213
213
|
- doc/release_notes/3.14.1.txt
|
214
|
+
- doc/release_notes/3.15.0.txt
|
214
215
|
files:
|
215
216
|
- CHANGELOG
|
216
217
|
- MIT-LICENSE
|
@@ -260,6 +261,7 @@ files:
|
|
260
261
|
- doc/release_notes/3.13.0.txt
|
261
262
|
- doc/release_notes/3.14.0.txt
|
262
263
|
- doc/release_notes/3.14.1.txt
|
264
|
+
- doc/release_notes/3.15.0.txt
|
263
265
|
- doc/release_notes/3.2.0.txt
|
264
266
|
- doc/release_notes/3.3.0.txt
|
265
267
|
- doc/release_notes/3.4.0.txt
|
@@ -493,7 +495,12 @@ files:
|
|
493
495
|
homepage: http://roda.jeremyevans.net
|
494
496
|
licenses:
|
495
497
|
- MIT
|
496
|
-
metadata:
|
498
|
+
metadata:
|
499
|
+
bug_tracker_uri: https://github.com/jeremyevans/roda/issues
|
500
|
+
changelog_uri: http://roda.jeremyevans.net/rdoc/files/CHANGELOG.html
|
501
|
+
documentation_uri: http://roda.jeremyevans.net/documentation.html
|
502
|
+
mailing_list_uri: https://groups.google.com/forum/#!forum/ruby-roda
|
503
|
+
source_code_uri: https://github.com/jeremyevans/roda
|
497
504
|
post_install_message:
|
498
505
|
rdoc_options: []
|
499
506
|
require_paths:
|