Module: Erubis::PrefixedLineEnhancer

Module | Erubis::PrefixedLineEnhancer
In: | erubis/enhancer.rb

regards lines starting with ’^[ \t]*%’ as program code

in addition you can specify prefix character (default ’%’)

this is language-independent.

### Methods

add_text init_generator

### Public Instance methods

add_text(src, text)

[Source]

    # File erubis/enhancer.rb, line 454
        def add_text(src, text)
          unless @prefixrexp
            @prefixchar ||= '%'
            @prefixrexp = Regexp.compile("^([ \\t]*)\\#{@prefixchar}(.*?\\r?\\n)")
          end
          pos = 0
          text2 = ''
          text.scan(@prefixrexp) do
            space = $1
            line  = $2
            space, line = '', $1 unless $2
            match = Regexp.last_match
            len   = match.begin(0) - pos
            str   = text[pos, len]
            pos   = match.end(0)
            if text2.empty?
              text2 = str
            else
              text2 << str
            end
            if line[0, 1] == @prefixchar
              text2 << space << line
            else
              super(src, text2)
              text2 = ''
              add_stmt(src, space + line)
            end
          end
          #rest = pos == 0 ? text : $'             # ruby1.8
          rest = pos == 0 ? text : text[pos..-1]   # ruby1.9
          unless text2.empty?
            text2 << rest if rest
            rest = text2
          end
          super(src, rest)
        end

init_generator(properties={})

[Source]

    # File erubis/enhancer.rb, line 449
        def init_generator(properties={})
          super
          @prefixchar = properties[:prefixchar]
        end

[Validate]