Module Erubis::OptimizedGenerator
In: erubis/engine/optimized.rb

Methods

Included Modules

Generator

Public Instance methods

[Source]

# File erubis/engine/optimized.rb, line 21
    def init_generator(properties={})
      super
      @escapefunc ||= "Erubis::XmlHelper.escape_xml"
      @initialized = false
      @prev_is_expr = false
    end

Protected Instance methods

[Source]

# File erubis/engine/optimized.rb, line 86
    def add_expr_debug(src, code)
      code.strip!
      s = (code.dump =~ /\A"(.*)"\z/) && $1
      src << ' $stderr.puts("*** debug: ' << s << '=#{(' << code << ').inspect}");'
    end

[Source]

# File erubis/engine/optimized.rb, line 80
    def add_expr_escaped(src, code)
      unless @initialized; src << "_buf = ''"; @initialized = true; end
      switch_to_expr(src)
      src << " << " << escaped_expr(code)
    end

[Source]

# File erubis/engine/optimized.rb, line 74
    def add_expr_literal(src, code)
      unless @initialized; src << "_buf = ''"; @initialized = true; end
      switch_to_expr(src)
      src << " << (" << code << ").to_s"
    end

[Source]

# File erubis/engine/optimized.rb, line 92
    def add_postamble(src)
      #super if @initialized
      src << "\n_buf\n" if @initialized
    end

[Source]

# File erubis/engine/optimized.rb, line 51
    def add_preamble(src)
      #@initialized = false
      #@prev_is_expr = false
    end

[Source]

# File erubis/engine/optimized.rb, line 67
    def add_stmt(src, code)
      switch_to_stmt(src) if @initialized
      #super
      src << code
      src << ';' unless code[-1] == ?\n
    end

[Source]

# File erubis/engine/optimized.rb, line 56
    def add_text(src, text)
      return if text.empty?
      if @initialized
        switch_to_expr(src)
        src << " << '" << escape_text(text) << "'"
      else
        src << "_buf = '" << escape_text(text) << "';"
        @initialized = true
      end
    end

[Source]

# File erubis/engine/optimized.rb, line 30
    def escape_text(text)
      text.gsub(/['\\]/, '\\\\\&')   # "'" => "\\'",  '\\' => '\\\\'
    end

[Source]

# File erubis/engine/optimized.rb, line 34
    def escaped_expr(code)
      @escapefunc ||= 'Erubis::XmlHelper.escape_xml'
      return "#{@escapefunc}(#{code})"
    end

[Source]

# File erubis/engine/optimized.rb, line 39
    def switch_to_expr(src)
      return if @prev_is_expr
      @prev_is_expr = true
      src << ' _buf'
    end

[Source]

# File erubis/engine/optimized.rb, line 45
    def switch_to_stmt(src)
      return unless @prev_is_expr
      @prev_is_expr = false
      src << ';'
    end

[Validate]