| Module | Erubis::SimplifyEnhancer |
| In: |
lib/erubis/enhancer.rb
|
get convert faster, but spaces around ’<%…%>’ are not trimmed.
this is language-independent.
| SIMPLE_REGEXP | = | /<%(=+|\#)?(.*?)-?%>/m | DEFAULT_REGEXP = /(^[ \t]*)?<%(=+|\#)?(.*?)-?%>([ \t]*\r?\n)?/m |
# File lib/erubis/enhancer.rb, line 343
343: def convert(input)
344: src = ""
345: add_preamble(src)
346: #regexp = pattern_regexp(@pattern)
347: pos = 0
348: input.scan(SIMPLE_REGEXP) do |indicator, code|
349: match = Regexp.last_match
350: index = match.begin(0)
351: text = input[pos, index - pos]
352: pos = match.end(0)
353: add_text(src, text)
354: if !indicator # <% %>
355: add_stmt(src, code)
356: elsif indicator[0] == ?\# # <%# %>
357: n = code.count("\n")
358: add_stmt(src, "\n" * n)
359: else # <%= %>
360: add_expr(src, code, indicator)
361: end
362: end
363: #rest = $' || input # ruby1.8
364: rest = pos == 0 ? input : input[pos..-1] # ruby1.9
365: add_text(src, rest)
366: add_postamble(src)
367: return src
368: end