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

### Methods

add_expr_debug add_expr_escaped add_expr_literal add_postamble add_preamble add_stmt add_text escape_text escaped_expr init_generator switch_to_expr switch_to_stmt

### Included Modules

Generator

### Public Instance methods

init_generator(properties={})

[Source]

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

### Protected Instance methods

add_expr_debug(src, code)

[Source]

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

add_expr_escaped(src, code)

[Source]

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

add_expr_literal(src, code)

[Source]

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

add_postamble(src)

[Source]

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

add_preamble(src)

[Source]

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

add_stmt(src, code)

[Source]

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

add_text(src, text)

[Source]

    # File erubis/engine/optimized.rb, line 55
        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

escape_text(text)

[Source]

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

escaped_expr(code)

[Source]

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

switch_to_expr(src)

[Source]

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

switch_to_stmt(src)

[Source]

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

[Validate]