| Module | Erubis::BiPatternEnhancer |
| In: |
lib/erubis/enhancer.rb
|
enable to use other embedded expression pattern (default is ’\[= =\]’).
notice! this is an experimental. spec may change in the future.
ex.
input = <<END
<% for item in list %>
<%= item %> : <%== item %>
[= item =] : [== item =]
<% end %>
END
class BiPatternEruby
include BiPatternEnhancer
end
eruby = BiPatternEruby.new(input, :bipattern=>'\[= =\]')
list = ['<a>', 'b&b', '"c"']
print eruby.result(binding())
## output
<a> : <a>
<a> : <a>
b&b : b&b
b&b : b&b
"c" : "c"
"c" : "c"
this is language independent.
# File lib/erubis/enhancer.rb, line 409
409: def initialize(input, properties={})
410: self.bipattern = properties[:bipattern] # or '\$\{ \}'
411: super
412: end
# File lib/erubis/enhancer.rb, line 421
421: def add_text(src, text)
422: return unless text
423: m = nil
424: text.scan(@bipattern_regexp) do |txt, indicator, code|
425: m = Regexp.last_match
426: super(src, txt)
427: add_expr(src, code, '=' + indicator)
428: end
429: #rest = $' || text # ruby1.8
430: rest = m ? text[m.end(0)..-1] : text # ruby1.9
431: super(src, rest)
432: end