erubi 1.3.0 → 1.4.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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +8 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -5
  5. data/lib/erubi.rb +20 -8
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33a3418c5b03e4cbef20234176d4b4d92308fa2a
4
- data.tar.gz: eba2a09e387237585fb664206eb917b6b19838a3
3
+ metadata.gz: 20b3fb23c6df5c201822001090290ca746da0c46
4
+ data.tar.gz: 1792657866eff6b28e95be1ab5a3463445be3a2b
5
5
  SHA512:
6
- metadata.gz: 2cb262e67db9196ce7a1b894dd611fdd62e9662d327ad6e68e95eb7226ca225c0dae98afa5d7edbda0ebb51d4711b8c0871d502876d3865e976965c0f853b1a2
7
- data.tar.gz: f85eda1b8942c038a4261dbad958cba7aeb7c72423fa7cf06101dd5b15a6420e4301e4a3cb84168b429f177f853f3775b146d815c5e87478f6f89c9cc6b98049
6
+ metadata.gz: e8e2c2e1e8bd7cbe522a1570f81fbd12a691c84a2332df3e1be760193b59b9ab73b6bf05f1d1944f64b902295d980229e63fe6098f1bebfa851f5816da81b1bb
7
+ data.tar.gz: 0b515eb522628f20f1843070c216ad1fc01a76a64235f87bc6ecec09116f20f6f97e77de85ba0518aeaa0fbe816c50e41096a197637f41b4edd24ba98791a614
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.4.0 (2017-01-20)
2
+
3
+ * Allow postambles to depend on internal state of engine (jeremyevans)
4
+
5
+ * Allow overriding of behavior for <%= and <%== tags to depend on which indicator was used (jeremyevans)
6
+
7
+ * Make whitespace handling for <% %> tags more compatible with Erubis for subclasses overriding add_text (jeremyevans)
8
+
1
9
  === 1.3.0 (2016-12-29)
2
10
 
3
11
  * Support :capture=>:explicit option in tilt support to use Erubi::CaptureEndEngine (jeremyevans)
@@ -1,5 +1,5 @@
1
1
  copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
2
- copyright(c) 2016 Jeremy Evans
2
+ copyright(c) 2016-2017 Jeremy Evans
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
5
5
  a copy of this software and associated documentation files (the
@@ -8,11 +8,11 @@ the following differences:
8
8
  * Works with ruby's --enable-frozen-string-literal option
9
9
  * Automatically freezes strings for template text when ruby optimizes it (on ruby 2.1+)
10
10
  * Escapes ' (apostrophe) when escaping for better XSS protection
11
- * Has 90% smaller memory footprint for base engine
11
+ * Has 88% smaller memory footprint for base engine
12
12
  * Has 75% smaller memory footprint for tilt support
13
13
  * Does no monkey patching (Erubis adds a method to Kernel)
14
14
  * Uses an immutable design (all options passed to the constructor, which returns a frozen object)
15
- * Has simpler internals (1 file, <100 lines of code)
15
+ * Has simpler internals (1 file, <150 lines of code)
16
16
  * Has an open development model (Erubis doesn't have a public source control repository or bug tracker)
17
17
  * Is not dead (Erubis hasn't been updated since 2011)
18
18
 
@@ -49,12 +49,12 @@ source:
49
49
  == Capturing
50
50
 
51
51
  Erubi does not support capturing block output into the template by default.
52
- However, it comes with an +erubi/capture+ file that supports capturing
53
- via <tt><%|=</tt> and <tt><%|==</tt> tags:
52
+ However, it comes with an +erubi/capture_end+ file that supports capturing
53
+ via <tt><%|=</tt>, <tt><%|==</tt>, <tt><%|</tt> tags:
54
54
 
55
55
  <%|= form do %>
56
56
  <input>
57
- <% end %>
57
+ <%| end %>
58
58
 
59
59
  This offers similar functionality to that offered by Rails' <tt><%=</tt>
60
60
  tags, but without the corner cases with that approach (which are due to
@@ -52,7 +52,7 @@ module Erubi
52
52
  # :src :: The initial value to use for the source code
53
53
  # :trim :: Whether to trim leading and trailing whitespace, true by default.
54
54
  def initialize(input, properties={})
55
- escape = properties.fetch(:escape){properties.fetch(:escape_html, false)}
55
+ @escape = escape = properties.fetch(:escape){properties.fetch(:escape_html, false)}
56
56
  trim = properties[:trim] != false
57
57
  @filename = properties[:filename]
58
58
  @bufvar = bufvar = properties[:bufvar] || properties[:outvar] || "_buf"
@@ -116,11 +116,7 @@ module Erubi
116
116
  when '='
117
117
  rspace = nil if tailch && !tailch.empty?
118
118
  add_text(lspace) if lspace
119
- if ((indicator == '=') ^ escape)
120
- add_expression_result(code)
121
- else
122
- add_expression_result_escaped(code)
123
- end
119
+ add_expression(indicator, code)
124
120
  add_text(rspace) if rspace
125
121
  when '#'
126
122
  n = code.count("\n") + (rspace ? 1 : 0)
@@ -134,7 +130,7 @@ module Erubi
134
130
  when '%'
135
131
  add_text("#{lspace}#{prefix||='<%'}#{code}#{tailch}#{postfix||='%>'}#{rspace}")
136
132
  when nil, '-'
137
- if trim
133
+ if trim && lspace && rspace
138
134
  add_code("#{lspace}#{code}#{rspace}")
139
135
  else
140
136
  add_text(lspace) if lspace
@@ -149,7 +145,7 @@ module Erubi
149
145
  add_text(rest)
150
146
 
151
147
  src << "\n" unless src[RANGE_LAST] == "\n"
152
- src << postamble
148
+ add_postamble(postamble)
153
149
  src << "; ensure\n #{bufvar} = __original_outvar\nend\n" if properties[:ensure]
154
150
  src.freeze
155
151
  freeze
@@ -168,6 +164,16 @@ module Erubi
168
164
  @src << ';' unless code[RANGE_LAST] == "\n"
169
165
  end
170
166
 
167
+ # Add the given ruby expression result to the template,
168
+ # escaping it based on the indicator given and escape flag.
169
+ def add_expression(indicator, code)
170
+ if ((indicator == '=') ^ @escape)
171
+ add_expression_result(code)
172
+ else
173
+ add_expression_result_escaped(code)
174
+ end
175
+ end
176
+
171
177
  # Add the result of Ruby expression to the template
172
178
  def add_expression_result(code)
173
179
  @src << " #{@bufvar} << (" << code << ').to_s;'
@@ -178,6 +184,12 @@ module Erubi
178
184
  @src << " #{@bufvar} << #{@escapefunc}((" << code << '));'
179
185
  end
180
186
 
187
+ # Add the given postamble to the src. Can be overridden in subclasses
188
+ # to make additional changes to src that depend on the current state.
189
+ def add_postamble(postamble)
190
+ src << postamble
191
+ end
192
+
181
193
  # Raise an exception, as the base engine class does not support handling other indicators.
182
194
  def handle(indicator, code, tailch, rspace, lspace)
183
195
  raise ArgumentError, "Invalid indicator: #{indicator}"
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.3.0
4
+ version: 1.4.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: 2016-12-29 00:00:00.000000000 Z
12
+ date: 2017-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt