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

Processing Instructions (PI) converter for XML. this class converts ’<?rb … ?>’ and ’${…}’ notation.

Methods

Included Modules

Erubis::Converter

Attributes

pi  [RW] 
prefix  [RW] 

Public Instance methods

[Source]

# File erubis/converter.rb, line 181
    def convert(input)
      code = super(input)
      return @header || @footer ? "#{@header}#{code}#{@footer}" : code
    end

[Source]

# File erubis/converter.rb, line 172
    def init_converter(properties={})
      super(properties)
      @trim    = !(properties[:trim] == false)
      @pi      = properties[:pi] if properties[:pi]
      @embchar = properties[:embchar]  || '@'
      @pattern = properties[:pattern]
      @pattern = '<% %>' if @pattern.nil?  #|| @pattern == true
    end

Protected Instance methods

[Source]

# File erubis/converter.rb, line 188
    def convert_input(codebuf, input)
      parse_stmts(codebuf, input)
      #parse_stmts2(codebuf, input)
    end

[Source]

# File erubis/converter.rb, line 216
    def parse_exprs(codebuf, input)
      unless @expr_pattern
        ch = Regexp.escape(@embchar)
        if @pattern
          left, right = @pattern.split(' ')
          @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}|#{left}(=+)(.*?)#{right}/
        else
          @expr_pattern = /#{ch}(!*)?\{(.*?)\}#{ch}/
        end
      end
      pos = 0
      input.scan(@expr_pattern) do |indicator1, code1, indicator2, code2|
        indicator = indicator1 || indicator2
        code = code1 || code2
        match = Regexp.last_match
        index = match.begin(0)
        text = input[pos, index - pos]
        pos = match.end(0)
        add_text(codebuf, text) # unless text.empty?
        add_pi_expr(codebuf, code, indicator)
      end
      rest = $' || input
      add_text(codebuf, rest)
    end

[Source]

# File erubis/converter.rb, line 193
    def parse_stmts(codebuf, input)
      #regexp = pattern_regexp(@pattern)
      @pi ||= 'e'
      @stmt_pattern ||= /(^[ \t]*)?<\?#{@pi}(?:-(\w+))?(\s.*?)\?>([ \t]*\r?\n)?/m
      pos = 0
      input.scan(@stmt_pattern) do |lspace, pi_arg, code, rspace|
        match = Regexp.last_match
        index = match.begin(0)
        text = input[pos, index - pos]
        pos = match.end(0)
        parse_exprs(codebuf, text) # unless text.empty?
        if @trim && lspace && rspace
          add_pi_stmt(codebuf, "#{lspace}#{code}#{rspace}", pi_arg)
        else
          add_text(codebuf, lspace)
          add_pi_stmt(codebuf, code, pi_arg)
          add_text(codebuf, rspace)
        end
      end
      rest = $' || input
      parse_exprs(codebuf, rest)
    end

[Validate]