erubi 1.4.0 → 1.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
  SHA1:
3
- metadata.gz: 20b3fb23c6df5c201822001090290ca746da0c46
4
- data.tar.gz: 1792657866eff6b28e95be1ab5a3463445be3a2b
3
+ metadata.gz: fd16f88fa55dfb16632b96ad51f1b9d8b4dfcb3a
4
+ data.tar.gz: 369980088c6de4f7309f53ccbc1f4d77c40569d7
5
5
  SHA512:
6
- metadata.gz: e8e2c2e1e8bd7cbe522a1570f81fbd12a691c84a2332df3e1be760193b59b9ab73b6bf05f1d1944f64b902295d980229e63fe6098f1bebfa851f5816da81b1bb
7
- data.tar.gz: 0b515eb522628f20f1843070c216ad1fc01a76a64235f87bc6ecec09116f20f6f97e77de85ba0518aeaa0fbe816c50e41096a197637f41b4edd24ba98791a614
6
+ metadata.gz: 5bea95cdd30ba995ffd760d40131dab30cfbbe0f4dd57c87957c8b8d55cd0a55b2e4c7fd92d692defc1e2d90ae7a0b564462d8c5b48babdd14947c7137be2708
7
+ data.tar.gz: a0850dc7e918bf33c5e32707f1747cdfa0cb2902f8308be7d4f19d120b006426e9efc5b384fde46c1a2b920d23fa7432a37fdaf08a636928355f0391b03df6b2
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.5.0 (2017-01-26)
2
+
3
+ * Drop tilt/erubi file, as tilt now ships with Erubi support (jeremyevans)
4
+
5
+ * Drop erubi/capture file, Erubi::CaptureEngine support (jeremyevans)
6
+
1
7
  === 1.4.0 (2017-01-20)
2
8
 
3
9
  * Allow postambles to depend on internal state of engine (jeremyevans)
@@ -1,7 +1,7 @@
1
1
  = Erubi
2
2
 
3
- Erubi is a ERB template engine for ruby. It is a simplified fork of Erubis, with
4
- the following differences:
3
+ Erubi is a ERB template engine for ruby. It is a simplified fork of Erubis, using
4
+ the same basic algorithm, with the following differences:
5
5
 
6
6
  * Handles postfix conditionals when using escaping (e.g. <tt><%= foo if bar %></tt>)
7
7
  * Supports frozen_string_literal: true in templates via :freeze option
@@ -31,21 +31,16 @@ Source code is available on GitHub at https://github.com/jeremyevans/erubi
31
31
 
32
32
  = Usage
33
33
 
34
- The expected usage is via tilt, and erubi ships with tilt 2 integration:
35
-
36
- require 'tilt/erubi'
37
- Tilt.new("filename.erb").render
38
-
39
- Requiring +tilt/erubi+ sets erubi as the default erb/rhtml template processor
40
- for tilt. In most cases, you can use Erubi as a replacement for Erubis if
41
- you are using tilt.
42
-
43
- You can use the library manually, but it's only useful to get the generated
44
- source:
34
+ Erubi only has built in support for retrieving the generated source for a
35
+ file:
45
36
 
46
37
  require 'erubi'
47
38
  eval(Erubi::Engine.new(File.read('filename.erb')).src)
48
39
 
40
+ Most users are will probably use Erubi via Rails or Tilt. Erubi is the default
41
+ erb template handler in Tilt 2.0.6+ and will be the default template handler in
42
+ Rails 5.1+.
43
+
49
44
  == Capturing
50
45
 
51
46
  Erubi does not support capturing block output into the template by default.
@@ -63,6 +58,12 @@ and <tt><%==</tt> tags, <tt><%|=</tt> captures by default and
63
58
  <tt><%|==</tt> captures and escapes by default, but this can be reversed
64
59
  via the +:escape_capture+ or +:escape+ options.
65
60
 
61
+ To use the capture_end support with tilt:
62
+
63
+ require 'tilt'
64
+ require 'erubi/capture_end'
65
+ Tilt.new("filename.erb", :engine_class=>Erubi::CaptureEndEngine).render
66
+
66
67
  = Reporting Bugs
67
68
 
68
69
  The bug tracker is located at https://github.com/jeremyevans/erubi/issues
@@ -22,9 +22,7 @@ if ENV['COVERAGE']
22
22
  end
23
23
 
24
24
  require 'erubi'
25
- require 'erubi/capture'
26
25
  require 'erubi/capture_end'
27
- require 'tilt/erubi'
28
26
  require 'minitest/spec'
29
27
  require 'minitest/autorun'
30
28
 
@@ -161,88 +159,6 @@ END3
161
159
  @a.must_equal 'bar'
162
160
  end
163
161
 
164
- [['', false], ['=', true]].each do |ind, escape|
165
- it "should allow <%|=#{ind} for capturing with CaptureEngine with :escape_capture => #{escape} and :escape => #{escape}" do
166
- @options[:bufvar] = '@a'
167
- @options[:capture] = true
168
- @options[:escape_capture] = escape
169
- @options[:escape] = !escape
170
- @options[:engine] = ::Erubi::CaptureEngine
171
- setup_foo
172
- check_output(<<END1, <<END2, <<END3){}
173
- <table>
174
- <tbody>
175
- <%|=#{ind} @foo.bar do %>
176
- <tr>
177
- <td><%=#{ind} 1 %></td>
178
- <td><%=#{ind} '&' %></td>
179
- </tr>
180
- <% end %>
181
- </tbody>
182
- </table>
183
- END1
184
- #{'__erubi = ::Erubi;' unless escape}@a = ::Erubi::Buffer.new; @a << '<table>
185
- <tbody>
186
- '; @a << ' '; @a.before_append!; @a.append= @foo.bar do @a << '
187
- '; @a << ' <tr>
188
- <td>'; @a << #{!escape ? '__erubi' : '::Erubi'}.h(( 1 )); @a << '</td>
189
- <td>'; @a << #{!escape ? '__erubi' : '::Erubi'}.h(( '&' )); @a << '</td>
190
- </tr>
191
- '; end
192
- @a << ' </tbody>
193
- </table>
194
- ';
195
- @a.to_s
196
- END2
197
- <table>
198
- <tbody>
199
- A
200
- <TR>
201
- <TD>1</TD>
202
- <TD>&AMP;</TD>
203
- </TR>
204
- B </tbody>
205
- </table>
206
- END3
207
- end
208
- end
209
-
210
- [['', true], ['=', false]].each do |ind, escape|
211
- it "should allow <%|=#{ind} for capturing with CaptureEngine with :escape => #{escape}" do
212
- @options[:bufvar] = '@a'
213
- @options[:capture] = true
214
- @options[:escape] = escape
215
- @options[:engine] = ::Erubi::CaptureEngine
216
- setup_foo
217
- check_output(<<END1, <<END2, <<END3){}
218
- <table>
219
- <tbody>
220
- <%|=#{ind} @foo.bar do %>
221
- <b><%=#{ind} '&' %></b>
222
- <% end %>
223
- </tbody>
224
- </table>
225
- END1
226
- #{'__erubi = ::Erubi;' if escape}@a = ::Erubi::Buffer.new; @a << '<table>
227
- <tbody>
228
- '; @a << ' '; @a.before_append!; @a.escape= @foo.bar do @a << '
229
- '; @a << ' <b>'; @a << #{escape ? '__erubi' : '::Erubi'}.h(( '&' )); @a << '</b>
230
- '; end
231
- @a << ' </tbody>
232
- </table>
233
- ';
234
- @a.to_s
235
- END2
236
- <table>
237
- <tbody>
238
- A
239
- &lt;B&gt;&amp;AMP;&lt;/B&gt;
240
- B </tbody>
241
- </table>
242
- END3
243
- end
244
- end
245
-
246
162
  [['', false], ['=', true]].each do |ind, escape|
247
163
  it "should allow <%|=#{ind} and <%| for capturing with CaptureEndEngine with :escape_capture => #{escape} and :escape => #{!escape}" do
248
164
  @options[:bufvar] = '@a'
@@ -284,7 +200,6 @@ END3
284
200
  [['', true], ['=', false]].each do |ind, escape|
285
201
  it "should allow <%|=#{ind} and <%| for capturing with CaptureEndEngine when with :escape => #{escape}" do
286
202
  @options[:bufvar] = '@a'
287
- @options[:capture] = true
288
203
  @options[:escape] = escape
289
204
  @options[:engine] = ::Erubi::CaptureEndEngine
290
205
  setup_bar
@@ -319,7 +234,6 @@ END3
319
234
 
320
235
  it "should allow <%|=#{ind} and <%| for nested capturing with CaptureEndEngine when with :escape => #{escape}" do
321
236
  @options[:bufvar] = '@a'
322
- @options[:capture] = true
323
237
  @options[:escape] = escape
324
238
  @options[:engine] = ::Erubi::CaptureEndEngine
325
239
  setup_bar
@@ -622,71 +536,6 @@ END3
622
536
 
623
537
  it "should raise an error if a tag is not handled when a custom regexp is used" do
624
538
  proc{Erubi::Engine.new('<%] %>', :regexp =>/<%(={1,2}|\]|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m)}.must_raise ArgumentError
625
- proc{Erubi::CaptureEngine.new('<%] %>', :regexp =>/<%(={1,2}|\]|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m)}.must_raise ArgumentError
626
- end
627
-
628
- it "should have working tilt support" do
629
- @list = ['&\'<>"2']
630
- Tilt::ErubiTemplate.new{<<END1}.render(self).must_equal(<<END2)
631
- <table>
632
- <tbody>
633
- <% i = 0
634
- @list.each_with_index do |item, i| %>
635
- <tr>
636
- <td><%= i+1 %></td>
637
- <td><%== item %></td>
638
- </tr>
639
- <% end %>
640
- </tbody>
641
- </table>
642
- <%== i+1 %>
643
- END1
644
- <table>
645
- <tbody>
646
- <tr>
647
- <td>1</td>
648
- <td>&amp;&#039;&lt;&gt;&quot;2</td>
649
- </tr>
650
- </tbody>
651
- </table>
652
- 1
653
- END2
654
- end
655
-
656
- it "should have working tilt support for capturing" do
657
- setup_foo
658
- Tilt::ErubiTemplate.new(:capture=>true, :outvar=>'@a'){<<END1}.render(self).must_equal(<<END2)
659
- 1<%|= @foo.bar do %>bar<% end %>2
660
- END1
661
- 1ABARB2
662
- END2
663
- end
664
-
665
- it "should have working tilt support for explicit capturing" do
666
- setup_bar
667
- Tilt::ErubiTemplate.new(:capture=>:explicit, :outvar=>'@a'){<<END1}.render(self).must_equal(<<END2)
668
- 1<%|= bar do %>b<%|= baz do %>e<%| end %>ar<%| end %>2
669
- END1
670
- 1ABCEDCEDARB2
671
- END2
672
- end
673
-
674
- it "should have working tilt support for specifying engine class" do
675
- setup_foo
676
- @a = 1
677
- Tilt::ErubiTemplate.new(:engine_class=>Erubi::CaptureEngine, :outvar=>'@a'){<<END1}.render(self).must_equal(<<END2)
678
- 1<%|= @foo.bar do %>bar<% end %>2
679
- END1
680
- 1ABARB2
681
- END2
682
- @a.must_equal 1
683
- end
684
-
685
- it "should have working tilt support for locals" do
686
- Tilt::ErubiTemplate.new{<<END1}.render(self, :b=>3).must_equal(<<END2)
687
- <%= b %>
688
- END1
689
- 3
690
- END2
539
+ proc{Erubi::CaptureEndEngine.new('<%] %>', :regexp =>/<%(={1,2}|\]|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m)}.must_raise ArgumentError
691
540
  end
692
541
  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.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-20 00:00:00.000000000 Z
12
+ date: 2017-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: tilt
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '2'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '2'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: minitest
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -53,9 +39,7 @@ files:
53
39
  - README.rdoc
54
40
  - Rakefile
55
41
  - lib/erubi.rb
56
- - lib/erubi/capture.rb
57
42
  - lib/erubi/capture_end.rb
58
- - lib/tilt/erubi.rb
59
43
  - test/test.rb
60
44
  homepage: https://github.com/jeremyevans/erubi
61
45
  licenses:
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'erubi'
4
-
5
- module Erubi
6
- # A buffer class used for templates that support captures
7
- class Buffer
8
- def initialize
9
- @bufs = [new_buffer]
10
- end
11
-
12
- # Return the current buffer
13
- def buffer
14
- @bufs.last
15
- end
16
-
17
- # Append to the current buffer
18
- def <<(str)
19
- buffer << str
20
- end
21
-
22
- # Add a new buffer, that future appends will go to.
23
- def before_append!
24
- @bufs << new_buffer
25
- end
26
-
27
- # Take the current buffer and append it to the previous buffer.
28
- def append=(_)
29
- buf = @bufs.pop
30
- buffer << buf.to_s
31
- end
32
-
33
- # Escape the current buffer and append it to the previous buffer,
34
- def escape=(_)
35
- buf = @bufs.pop
36
- buffer << escape(buf.to_s)
37
- end
38
-
39
- # Return the current buffer, as a string.
40
- def to_s
41
- buffer.to_s
42
- end
43
-
44
- private
45
-
46
- # An object to use for the underlying buffers.
47
- def new_buffer
48
- String.new
49
- end
50
-
51
- # HTML/XML escape the given string.
52
- def escape(str)
53
- ::Erubi.h(str)
54
- end
55
- end
56
-
57
- # An engine class that supports capturing blocks via the <%|= and <%|== tags.
58
- class CaptureEngine < Engine
59
- # Initializes the engine. Accepts the same arguments as ::Erubi::Engine, and these
60
- # additional options:
61
- # :escape_capture :: Whether to make <%|= escape by default, and <%|== not escape by default,
62
- # defaults to the same value as :escape.
63
- def initialize(input, properties={})
64
- properties = Hash[properties]
65
- escape = properties.fetch(:escape){properties.fetch(:escape_html, false)}
66
- @escape_capture = properties.fetch(:escape_capture, escape)
67
- properties[:regexp] ||= /<%(\|?={1,2}|-|\#|%)?(.*?)([-=])?%>([ \t]*\r?\n)?/m
68
- properties[:bufval] ||= "::Erubi::Buffer.new"
69
- super
70
- end
71
-
72
- private
73
-
74
- # Handle the <%|= and <%|== tags
75
- def handle(indicator, code, tailch, rspace, lspace)
76
- case indicator
77
- when '|=', '|=='
78
- rspace = nil if tailch && !tailch.empty?
79
- add_text(lspace) if lspace
80
- meth = ((indicator == '|=') ^ @escape_capture) ? 'append' : 'escape'
81
- src << " #{@bufvar}.before_append!; #{@bufvar}.#{meth}= " << code
82
- add_text(rspace) if rspace
83
- else
84
- super
85
- end
86
- end
87
- end
88
- end
@@ -1,35 +0,0 @@
1
- require 'tilt'
2
- require 'tilt/template'
3
- require 'erubi'
4
-
5
- module Tilt
6
- # Erubi (a simplified version of Erubis) template implementation
7
- class ErubiTemplate < Template
8
- def prepare
9
- @options.merge!(:preamble => false, :postamble => false, :ensure=>true)
10
-
11
- engine_class = if @options[:engine_class]
12
- @options[:engine_class]
13
- elsif capture = @options[:capture]
14
- if capture == :explicit
15
- Erubi::CaptureEndEngine
16
- else
17
- Erubi::CaptureEngine
18
- end
19
- else
20
- Erubi::Engine
21
- end
22
-
23
- @engine = engine_class.new(data, @options)
24
- @outvar = @engine.bufvar
25
- @src = @engine.src.dup
26
- @engine
27
- end
28
-
29
- def precompiled_template(locals)
30
- @src
31
- end
32
-
33
- Tilt.register self, 'erb', 'rhtml', 'erubi'
34
- end
35
- end