padrino-helpers 0.14.0.rc2 → 0.14.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: 43d09f356d574dade9184047d8cfea562f7c05dc
4
- data.tar.gz: e22cdc11c645e69234b352533d57f1d178f933fc
3
+ metadata.gz: b68d97255577ac8149b6bcb22bbd28d9c3d7e17c
4
+ data.tar.gz: 963950d1cabb60cd1df99fa50d3e2a4ceef23479
5
5
  SHA512:
6
- metadata.gz: fb80bdd1e58b3f2f53509ca8d4bae186a4a75799c2f4e191ebccffbe7325364b7d25fac93f6a9ff4360709972759fd12cc4b043f333e1bae4343b12731b1a595
7
- data.tar.gz: 7e3506a11a695b0755abc1e5f8bf892566ee2bcb8e0b55146f78c4d0b24226bf572cf327ffdc91918e985f9adddc9165936ce13acf36b56db3f9552961c36dc1
6
+ metadata.gz: 51a22336e7d329069ad6722eba3f853e2230e212105dcedd64b2dc417cb236d4776f9d7bf656ec8b849e9f4186b57af92c0d9eb45b40bc2c6e0456d299ee0fe8
7
+ data.tar.gz: 0e020f0a6b89ed5d496b02c595ecee89849a63398cdfc599d738f43a0365f2d85e696b8b6886b1f78921cbb202bb518aaf0bbf34d408a677da3b86916f01beb8
@@ -99,5 +99,5 @@ es:
99
99
  template:
100
100
  header:
101
101
  one: "1 error impidió que %{model} se guardara"
102
- other: "%{count} erroress impidieron que %{model} se guardara"
102
+ other: "%{count} errores impidieron que %{model} se guardara"
103
103
  body: "Hay problemas con los siguientes campos:"
@@ -23,6 +23,7 @@ module Padrino
23
23
  end
24
24
  OutputHelpers.register(:erb, ErbHandler)
25
25
  OutputHelpers.register(:erubis, ErbHandler)
26
+ OutputHelpers.register(:erubi, ErbHandler)
26
27
  end
27
28
  end
28
29
  end
@@ -31,7 +31,7 @@ module Padrino
31
31
  # @note If using this from Sinatra, pass explicit +:engine+ option
32
32
  #
33
33
  def partial(template, options={}, &block)
34
- options = { :locals => {}, :layout => false }.update(options)
34
+ options = options.dup
35
35
  explicit_engine = options.delete(:engine)
36
36
 
37
37
  path, _, name = template.to_s.rpartition(File::SEPARATOR)
@@ -44,15 +44,15 @@ module Padrino
44
44
  [[options.delete(:object)], nil]
45
45
  end
46
46
 
47
- locals = options[:locals]
47
+ locals = options.delete(:locals) || {}
48
48
  items.each_with_object(SafeBuffer.new) do |item,html|
49
49
  locals[item_name] = item if item
50
50
  locals["#{item_name}_counter".to_sym] = counter += 1 if counter
51
51
  content =
52
52
  if block_given?
53
- concat_content render(explicit_engine, template_path, options){ capture_html(&block) }
53
+ concat_content(render(explicit_engine, template_path, options, locals) { capture_html(&block) })
54
54
  else
55
- render(explicit_engine, template_path, options)
55
+ render(explicit_engine, template_path, options, locals)
56
56
  end
57
57
  html.safe_concat content if content
58
58
  end
@@ -65,7 +65,6 @@ module Padrino
65
65
  fail "gem 'tilt' is required" unless defined?(::Tilt)
66
66
 
67
67
  def render(engine, file=nil, options={}, locals=nil, &block)
68
- locals ||= options[:locals] || {}
69
68
  engine, file = file, engine if file.nil?
70
69
  template_engine = engine ? ::Tilt[engine] : ::Tilt.default_mapping[file]
71
70
  fail "Engine #{engine.inspect} is not registered with Tilt" unless template_engine
@@ -382,3 +382,12 @@ unless defined? Padrino::Rendering::SlimTemplate
382
382
  require 'padrino/rendering/slim_template'
383
383
  end
384
384
  end
385
+
386
+ unless defined? Padrino::Rendering::ErubiTemplate
387
+ begin
388
+ require 'erubi'
389
+ rescue LoadError
390
+ else
391
+ require 'padrino/rendering/erubi_template'
392
+ end
393
+ end
@@ -0,0 +1,37 @@
1
+ module Padrino
2
+ module Rendering
3
+ module Erubi
4
+ module SafeBufferEnhancer
5
+ def add_expression_result(code)
6
+ @src << " @__in_ruby_literal = true; #{bufvar}.concat((" << code << ').to_s); @__in_ruby_literal = false;'
7
+ end
8
+
9
+ def add_expression_result_escaped(code)
10
+ @src << " #{bufvar}.safe_concat (" << code << ");"
11
+ end
12
+
13
+ def add_text(text)
14
+ @src << " #{bufvar}.safe_concat '" << text.gsub(/['\\]/, '\\\\\&') << "';" unless text.empty?
15
+ end
16
+ end
17
+ end
18
+
19
+ class SafeErubi < ::Erubi::Engine
20
+ include Erubi::SafeBufferEnhancer
21
+ end
22
+
23
+ class ErubiTemplate < Tilt::ErubiTemplate
24
+ def precompiled_preamble(*)
25
+ "__in_erb_template = true\n" << super
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Tilt.prefer(Padrino::Rendering::ErubiTemplate, :erb)
32
+
33
+ Padrino::Rendering.engine_configurations[:erb] = {
34
+ :bufval => "SafeBuffer.new",
35
+ :bufvar => "@_out_buf",
36
+ :engine_class => Padrino::Rendering::SafeErubi
37
+ }
@@ -622,6 +622,23 @@ describe "Rendering" do
622
622
  assert_equal 'this is a <span>span</span>', body
623
623
  end
624
624
 
625
+ it 'should render unescaped html on == token (Erubis and Erubi)' do
626
+ skip if ENV['ERB_ENGINE'] == 'stdlib'
627
+ mock_app do
628
+ layout do
629
+ "<%= yield %>"
630
+ end
631
+
632
+ get "/" do
633
+ render :erb, '<%== "<script></script>" %>'
634
+ end
635
+ end
636
+
637
+ get "/"
638
+ assert ok?
639
+ assert_equal "<script></script>", body
640
+ end
641
+
625
642
  it 'should render haml to a SafeBuffer' do
626
643
  mock_app do
627
644
  layout do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0.rc2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-01-19 00:00:00.000000000 Z
14
+ date: 2017-03-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.14.0.rc2
22
+ version: 0.14.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.14.0.rc2
29
+ version: 0.14.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: tilt
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,7 @@ files:
123
123
  - lib/padrino/core_ext/output_safety.rb
124
124
  - lib/padrino/rendering.rb
125
125
  - lib/padrino/rendering/erb_template.rb
126
+ - lib/padrino/rendering/erubi_template.rb
126
127
  - lib/padrino/rendering/erubis_template.rb
127
128
  - lib/padrino/rendering/haml_template.rb
128
129
  - lib/padrino/rendering/slim_template.rb
@@ -242,12 +243,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
243
  version: '0'
243
244
  required_rubygems_version: !ruby/object:Gem::Requirement
244
245
  requirements:
245
- - - ">"
246
+ - - ">="
246
247
  - !ruby/object:Gem::Version
247
- version: 1.3.1
248
+ version: 1.3.6
248
249
  requirements: []
249
250
  rubyforge_project: padrino-helpers
250
- rubygems_version: 2.6.6
251
+ rubygems_version: 2.6.10
251
252
  signing_key:
252
253
  specification_version: 4
253
254
  summary: Helpers for padrino