@@ -134,31 +134,31 @@ def initialize(input, properties={})
134
134
end
135
135
136
136
is_bol = rspace
137
- add_text ( text )
137
+ add_text ( text ) if text
138
138
case ch
139
139
when '='
140
140
rspace = nil if tailch && !tailch . empty?
141
- add_text ( lspace )
141
+ add_text ( lspace ) if lspace
142
142
add_expression ( indicator , code )
143
- add_text ( rspace )
143
+ add_text ( rspace ) if rspace
144
144
when '#'
145
145
n = code . count ( "\n " ) + ( rspace ? 1 : 0 )
146
146
if trim && lspace && rspace
147
147
add_code ( "\n " * n )
148
148
else
149
- add_text ( lspace )
149
+ add_text ( lspace ) if lspace
150
150
add_code ( "\n " * n )
151
- add_text ( rspace )
151
+ add_text ( rspace ) if rspace
152
152
end
153
153
when '%'
154
154
add_text ( "#{ lspace } #{ literal_prefix } #{ code } #{ tailch } #{ literal_postfix } #{ rspace } " )
155
155
when nil , '-'
156
156
if trim && lspace && rspace
157
157
add_code ( "#{ lspace } #{ code } #{ rspace } " )
158
158
else
159
- add_text ( lspace )
159
+ add_text ( lspace ) if lspace
160
160
add_code ( code )
161
- add_text ( rspace )
161
+ add_text ( rspace ) if rspace
162
162
end
163
163
else
164
164
handle ( indicator , code , tailch , rspace , lspace )
@@ -177,15 +177,16 @@ def initialize(input, properties={})
177
177
private
178
178
179
179
# Add raw text to the template. Modifies argument if argument is mutable as a memory optimization.
180
+ # Must be called with a string, cannot be called with nil (Rails's subclass depends on it).
180
181
def add_text ( text )
181
- if text && !text . empty?
182
- if text . frozen?
183
- text = text . gsub ( /['\\ ]/ , '\\\\\&' )
184
- else
185
- text . gsub! ( /['\\ ]/ , '\\\\\&' )
186
- end
187
- @src << " " << @bufvar << " << '" << text << TEXT_END
182
+ return if text . empty?
183
+
184
+ if text . frozen?
185
+ text = text . gsub ( /['\\ ]/ , '\\\\\&' )
186
+ else
187
+ text . gsub! ( /['\\ ]/ , '\\\\\&' )
188
188
end
189
+ @src << " " << @bufvar << " << '" << text << TEXT_END
189
190
end
190
191
191
192
# Add ruby code to the template
0 commit comments