Module Erubis::Basic::Converter
In: erubis/converter.rb

basic converter which supports ’<% … %>’ notation.

Methods

Included Modules

Erubis::Converter

Constants

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

Attributes

pattern  [RW] 
trim  [RW] 

Public Instance methods

add expression code to src

[Source]

# File erubis/converter.rb, line 133
    def add_expr(src, code, indicator)
      case indicator
      when '='
        @escape ? add_expr_escaped(src, code) : add_expr_literal(src, code)
      when '=='
        @escape ? add_expr_literal(src, code) : add_expr_escaped(src, code)
      when '==='
        add_expr_debug(src, code)
      end
    end

[Source]

# File erubis/converter.rb, line 94
    def convert_input(src, input)
      regexp = pattern_regexp(@pattern)
      pos = 0
      input.scan(regexp) do |lspace, indicator, code, rspace|
        match = Regexp.last_match()
        index = match.begin(0)
        text  = input[pos, index - pos]
        pos   = match.end(0)
        add_text(src, text)
        ## * when '<%= %>', do nothing
        ## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
        if !indicator               # <% %>
          if @trim && lspace && rspace
            add_stmt(src, "#{lspace}#{code}#{rspace}")
          else
            add_text(src, lspace) if lspace
            add_stmt(src, code)
            add_text(src, rspace) if rspace
          end
        elsif indicator[0] == ?\#   # <%# %>
          n = code.count("\n") + (rspace ? 1 : 0)
          if @trim && lspace && rspace
            add_stmt(src, "\n" * n)
          else
            add_text(src, lspace) if lspace
            add_stmt(src, "\n" * n)
            add_text(src, rspace) if rspace
          end
        else                        # <%= %>
          add_text(src, lspace) if lspace
          add_expr(src, code, indicator)
          add_text(src, rspace) if rspace
        end
      end
      rest = $' || input     # add input when no matched
      add_text(src, rest)
    end

[Source]

# File erubis/converter.rb, line 73
    def init_converter(properties={})
      super(properties)
      @pattern   = properties[:pattern]
      @trim      = properties[:trim] != false
    end

Protected Instance methods

return regexp of pattern to parse eRuby script

[Source]

# File erubis/converter.rb, line 83
    def pattern_regexp(pattern=@pattern)
      if pattern.nil? || pattern == '<% %>'
        return DEFAULT_REGEXP
      else
        prefix, postfix = pattern.split()
        #return /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
        return /(^[ \t]*)?#{prefix}(=+|\#)?(.*?)-?#{postfix}([ \t]*\r?\n)?/m
      end
    end

[Validate]