Methods

Class/Module Index [+]

Quicksearch

Erubis::SimplifyEnhancer

get convert faster, but spaces around ‘<%…%>’ are not trimmed.

this is language-independent.

Constants

SIMPLE_REGEXP

DEFAULT_REGEXP = /(^[ t]*)?<%(=+|#)?(.*?)-?%>([ t]*r?n)?/m

Public Instance Methods

convert(input) click to toggle source
# File lib/erubis/enhancer.rb, line 342
def convert(input)
  src = ""
  add_preamble(src)
  #regexp = pattern_regexp(@pattern)
  pos = 0
  input.scan(SIMPLE_REGEXP) do |indicator, code|
    match = Regexp.last_match
    index = match.begin(0)
    text  = input[pos, index - pos]
    pos   = match.end(0)
    add_text(src, text)
    if !indicator              # <% %>
      add_stmt(src, code)
    elsif indicator[0] == \#\  # <%# %>
      n = code.count("\n")
      add_stmt(src, "\n" * n)
    else                       # <%= %>
      add_expr(src, code, indicator)
    end
  end
  #rest = $' || input                      # ruby1.8
  rest = pos == 0 ? input : input[pos..-1]  # ruby1.9
  add_text(src, rest)
  add_postamble(src)
  return src
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.