erubi 1.7.1 → 1.8.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
  SHA256:
3
- metadata.gz: f90a1816343b873297c5d0f5cc2a4d5506c129b3f7613a63cdb34afa82cb28ee
4
- data.tar.gz: ed8b6d7739ebae9db5818bebd6c42120a155da3d1eef8732f1d1e2b64bfdf417
3
+ metadata.gz: 30bbae115393cc4d2ff05acd506ebd7616aad0797454c91766b379bfbfecef8b
4
+ data.tar.gz: 4dd7876504af9f3a17674875daad4233b9731c7bd3f195ecdf2e2507a2fa33b1
5
5
  SHA512:
6
- metadata.gz: 56b1f608a9f0f049ae3523afaf8ff1ab0970290f4adb703a1e3b949ee476ddb2347d550e20cef140ec7afa72d1d34bc35d9fd8404c5eb94f43b5fcf644d7d031
7
- data.tar.gz: d8027fd9255e838d6c4df2064d37d5e2f2fa55c65bbd783b983438684a229706a8d35e3d2fbbaee79ffca0785a68804545acbb40c66ae9e1640322b501c17ff8
6
+ metadata.gz: 380753f81d65b28686ccc285bb77ed998fe95ef179fea87b28c74701c833182225ba22f544fbc2276cad1f5d1c8309a3c837e5e78ba120806b49b8b675d2ba30
7
+ data.tar.gz: 006365ddcb013ebb47789055993e176640ba8f285b4bb718c85d9a0793d7ba428587adab203976dc068dcb7fc0d466e76362f6fbcab7832d7463dfc05a7e3934
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.8.0 (2018-12-18)
2
+
3
+ * Support :yield_returns_buffer option in capture_end for always returning the (potentially modified) buffer in <%|= tags (evanleck) (#15)
4
+
1
5
  === 1.7.1 (2018-03-05)
2
6
 
3
7
  * Make whitespace handling for <%# %> tags more compatible with Erubis (jeremyevans) (#14)
@@ -63,6 +63,38 @@ To use the capture_end support with tilt:
63
63
  require 'erubi/capture_end'
64
64
  Tilt.new("filename.erb", :engine_class=>Erubi::CaptureEndEngine).render
65
65
 
66
+ When using the capture_end support, any methods (such as +form+ in the example
67
+ above) should return the (potentially modified) buffer. Since the buffer
68
+ variable is a local variable and not an instance variable by default, you'll
69
+ probably want to set the +:bufvar+ variable when using the capture_end
70
+ support to an instance variable, and have any methods used access that
71
+ instance variable. Example:
72
+
73
+ def form
74
+ @_buf << "<form>"
75
+ yield
76
+ @_buf << "</form>"
77
+ @_buf
78
+ end
79
+
80
+ puts eval(Erubi::CaptureEndEngine.new(<<-END, :bufvar=>:@_buf).src)
81
+ before
82
+ <%|= form do %>
83
+ inside
84
+ <%| end %>
85
+ after
86
+ END
87
+
88
+ # Output:
89
+ # before
90
+ # <form>
91
+ # inside
92
+ # </form>
93
+ # after
94
+
95
+ Alternatively, passing the option +:yield_returns_buffer => true+ will return the
96
+ buffer captured by the block instead of the last expression in the block.
97
+
66
98
  = Reporting Bugs
67
99
 
68
100
  The bug tracker is located at https://github.com/jeremyevans/erubi/issues
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Erubi
4
- VERSION = '1.7.1'
4
+ VERSION = '1.8.0'
5
5
  RANGE_ALL = 0..-1
6
6
 
7
7
  if RUBY_VERSION >= '1.9'
@@ -10,10 +10,17 @@ module Erubi
10
10
  # additional options:
11
11
  # :escape_capture :: Whether to make <%|= escape by default, and <%|== not escape by default,
12
12
  # defaults to the same value as :escape.
13
+ # :yield_returns_buffer :: Whether to have <%| tags insert the buffer as an expression, so that
14
+ # <%| end %> tags will have the buffer be the last expression inside
15
+ # the block, and therefore have the buffer be returned by the yield
16
+ # expression. Normally the buffer will be returned anyway, but there
17
+ # are cases where the last expression will not be the buffer,
18
+ # and therefore a different object will be returned.
13
19
  def initialize(input, properties={})
14
20
  properties = Hash[properties]
15
21
  escape = properties.fetch(:escape){properties.fetch(:escape_html, false)}
16
22
  @escape_capture = properties.fetch(:escape_capture, escape)
23
+ @yield_returns_buffer = properties.fetch(:yield_returns_buffer, false)
17
24
  @bufval = properties[:bufval] ||= 'String.new'
18
25
  @bufstack = '__erubi_stack'
19
26
  properties[:regexp] ||= /<%(\|?={1,2}|-|\#|%|\|)?(.*?)([-=])?%>([ \t]*\r?\n)?/m
@@ -34,7 +41,8 @@ module Erubi
34
41
  when '|'
35
42
  rspace = nil if tailch && !tailch.empty?
36
43
  add_text(lspace) if lspace
37
- src << code << ")).to_s; ensure; #{@bufvar} = #{@bufstack}.pop; end;"
44
+ result = @yield_returns_buffer ? " #{@bufvar}; " : ""
45
+ src << result << code << ")).to_s; ensure; #{@bufvar} = #{@bufstack}.pop; end;"
38
46
  add_text(rspace) if rspace
39
47
  else
40
48
  super
@@ -23,6 +23,8 @@ end
23
23
 
24
24
  require 'erubi'
25
25
  require 'erubi/capture_end'
26
+
27
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
26
28
  require 'minitest/spec'
27
29
  require 'minitest/autorun'
28
30
 
@@ -663,4 +665,110 @@ END3
663
665
  proc{Erubi::Engine.new('<%] %>', :regexp =>/<%(={1,2}|\]|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m)}.must_raise ArgumentError
664
666
  proc{Erubi::CaptureEndEngine.new('<%] %>', :regexp =>/<%(={1,2}|\]|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m)}.must_raise ArgumentError
665
667
  end
668
+
669
+ it "should respect the :yield_returns_buffer option for making templates return the (potentially modified) buffer" do
670
+ @options[:engine] = ::Erubi::CaptureEndEngine
671
+ @options[:bufvar] = '@a'
672
+
673
+ def self.bar
674
+ a = String.new
675
+ a << "a"
676
+ yield 'burgers'
677
+ case b = (yield 'salads')
678
+ when String
679
+ a << b
680
+ a << 'b'
681
+ a.upcase
682
+ end
683
+ end
684
+
685
+ check_output(<<END1, <<END2, <<END3){}
686
+ <%|= bar do |item| %>
687
+ Let's eat <%= item %>!
688
+ <% nil %><%| end %>
689
+ END1
690
+ @a = String.new;begin; (__erubi_stack ||= []) << @a; @a = String.new; __erubi_stack.last << (( bar do |item| @a << '
691
+ '; @a << 'Let\\'s eat '; @a << ( item ).to_s; @a << '!
692
+ '; nil ; end )).to_s; ensure; @a = __erubi_stack.pop; end; @a << '
693
+ ';
694
+ @a.to_s
695
+ END2
696
+
697
+ END3
698
+
699
+ @options[:yield_returns_buffer] = true
700
+
701
+ check_output(<<END1, <<END2, <<END3) {}
702
+ <%|= bar do |item| %>
703
+ Let's eat <%= item %>!
704
+ <% nil %><%| end %>
705
+ END1
706
+ @a = String.new;begin; (__erubi_stack ||= []) << @a; @a = String.new; __erubi_stack.last << (( bar do |item| @a << '
707
+ '; @a << 'Let\\'s eat '; @a << ( item ).to_s; @a << '!
708
+ '; nil ; @a; end )).to_s; ensure; @a = __erubi_stack.pop; end; @a << '
709
+ ';
710
+ @a.to_s
711
+ END2
712
+ A
713
+ LET'S EAT BURGERS!
714
+
715
+ LET'S EAT SALADS!
716
+ B
717
+ END3
718
+ end
719
+
720
+ it "should respect the :yield_returns_buffer option for making templates return the (potentially modified) buffer as the result of the block" do
721
+ @options[:engine] = ::Erubi::CaptureEndEngine
722
+ @options[:yield_returns_buffer] = true
723
+
724
+ def self.bar(foo = nil)
725
+ if foo.nil?
726
+ yield
727
+ else
728
+ foo
729
+ end
730
+ end
731
+
732
+ check_output(<<END1, <<END2, <<END3) {}
733
+ <%|= bar do %>
734
+ Let's eat the tacos!
735
+ <%| end %>
736
+
737
+ Delicious!
738
+ END1
739
+ _buf = String.new;begin; (__erubi_stack ||= []) << _buf; _buf = String.new; __erubi_stack.last << (( bar do _buf << '
740
+ '; _buf << 'Let\\'s eat the tacos!
741
+ '; _buf; end )).to_s; ensure; _buf = __erubi_stack.pop; end; _buf << '
742
+ '; _buf << '
743
+ Delicious!
744
+ ';
745
+ _buf.to_s
746
+ END2
747
+
748
+ Let's eat the tacos!
749
+
750
+
751
+ Delicious!
752
+ END3
753
+
754
+ check_output(<<END1, <<END2, <<END3) {}
755
+ <%|= bar("Don't eat the burgers!") do %>
756
+ Let's eat burgers!
757
+ <%| end %>
758
+
759
+ Delicious!
760
+ END1
761
+ _buf = String.new;begin; (__erubi_stack ||= []) << _buf; _buf = String.new; __erubi_stack.last << (( bar(\"Don't eat the burgers!\") do _buf << '
762
+ '; _buf << 'Let\\'s eat burgers!
763
+ '; _buf; end )).to_s; ensure; _buf = __erubi_stack.pop; end; _buf << '
764
+ '; _buf << '
765
+ Delicious!
766
+ ';
767
+ _buf.to_s
768
+ END2
769
+ Don't eat the burgers!
770
+
771
+ Delicious!
772
+ END3
773
+ end
666
774
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erubi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-05 00:00:00.000000000 Z
12
+ date: 2018-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.7.3
71
+ rubygems_version: 2.7.6
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Small ERB Implementation