Module Erubis::CppGenerator
In: erubis/engine/ecpp.rb

Methods

Included Modules

Generator

Public Instance methods

[Source]

# File erubis/engine/ecpp.rb, line 72
    def add_expr_debug(src, code)
      code.strip!
      src << @indent if src.empty? || src[-1] == ?\n
      src << " std::cerr << \"*** debug: #{code.gsub(/(")/, '\\\&')}=\" << (#{code});"
    end

[Source]

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

[Source]

# File erubis/engine/ecpp.rb, line 62
    def add_expr_literal(src, code)
      src << @indent if src.empty? || src[-1] == ?\n
      src << " _buf << (" << code.strip << ");"
    end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

# File erubis/engine/ecpp.rb, line 23
    def init_generator(properties={})
      super
      @escapefunc ||= "escape"
      @indent = properties[:indent] || ''
      @bufvar = properties[:bufvar] || '_buf'
    end

[Validate]