Module | Erubis::BiPatternEnhancer |
In: |
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 erubis/enhancer.rb, line 408 def initialize(input, properties={}) self.bipattern = properties[:bipattern] # or '\$\{ \}' super end
# File erubis/enhancer.rb, line 420 def add_text(src, text) return unless text m = nil text.scan(@bipattern_regexp) do |txt, indicator, code| m = Regexp.last_match super(src, txt) add_expr(src, code, '=' + indicator) end #rest = $' || text # ruby1.8 rest = m ? text[m.end(0)..-1] : text # ruby1.9 super(src, rest) end