Module: Erubis::CGenerator

Module | Erubis::CGenerator
In: | erubis/engine/ec.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

### Included Modules

Generator

### Public Instance methods

add_expr_debug(src, code)

[Source]

    # File erubis/engine/ec.rb, line 73
        def add_expr_debug(src, code)
          code.strip!
          s = nil
          if code =~ /\A\".*?\"\s*,\s*(.*)/
            s = $1.gsub(/[%"]/, '\\\1') + '='
          end
          src << @indent if src.empty? || src[-1] == ?\n
          src << " fprintf(stderr, \"*** debug: #{s}\" #{code});"
        end

add_expr_escaped(src, code)

[Source]

    # File erubis/engine/ec.rb, line 68
        def add_expr_escaped(src, code)
          src << @indent if src.empty? || src[-1] == ?\n
          src << ' ' << escaped_expr(code) << ';'
        end

add_expr_literal(src, code)

[Source]

    # File erubis/engine/ec.rb, line 63
        def add_expr_literal(src, code)
          src << @indent if src.empty? || src[-1] == ?\n
          src << " fprintf(#{@out}, " << code.strip << ');'
        end

add_postamble(src)

[Source]

    # File erubis/engine/ec.rb, line 83
        def add_postamble(src)
          # empty
        end

add_preamble(src)

[Source]

    # File erubis/engine/ec.rb, line 31
        def add_preamble(src)
          src << "#line 1 \"#{self.filename}\"\n" if self.filename
        end

add_stmt(src, code)

[Source]

    # File erubis/engine/ec.rb, line 59
        def add_stmt(src, code)
          src << code
        end

add_text(src, text)

[Source]

    # File erubis/engine/ec.rb, line 45
        def add_text(src, text)
          return if text.empty?
          src << (src.empty? || src[-1] == ?\n ? @indent : ' ')
          src << "fputs("
          i = 0
          text.each_line do |line|
            src << "\n" << @indent << '      ' if i > 0
            i += 1
            src << '"' << escape_text(line) << '"'
          end
          src << ", #{@out});"   #<< (text[-1] == ?\n ? "\n" : "")
          src << "\n" if text[-1] == ?\n
        end

escape_text(text)

[Source]

    # File erubis/engine/ec.rb, line 35
        def escape_text(text)
          @@table_ ||= { "\r"=>"\\r", "\n"=>"\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
          text.gsub!(/[\r\n\t"\\]/) { |m| @@table_[m] }
          return text
        end

escaped_expr(code)

[Source]

    # File erubis/engine/ec.rb, line 41
        def escaped_expr(code)
          return "#{@escapefunc}(#{code.strip}, #{@out})"
        end

init_generator(properties={})

[Source]

    # File erubis/engine/ec.rb, line 24
        def init_generator(properties={})
          super
          @escapefunc ||= "escape"
          @indent = properties[:indent] || ''
          @out = properties[:out] || 'stdout'
        end

[Validate]