Class Kwartz::BaseTranslator
In: kwartz/translator.rb
Parent: Translator

concrete class for visitor pattern

see ErbTranslator, PhpTranslator, JstlTranslator, and so on for detail.

Methods

Attributes

escape  [RW] 
footer  [RW] 
header  [RW] 

Public Class methods

[Source]

# File kwartz/translator.rb, line 83
    def initialize(marks=[], properties={})
      @stmt_l, @stmt_r, @expr_l, @expr_r, @escape_l, @escape_r = marks
      @nl = properties[:nl] || "\n"
      @escape = properties[:escape]
      @escape = Config::PROPERTY_ESCAPE if @escape == nil
      @header = properties[:header]
      @footer = properties[:footer]
    end

Public Instance methods

[Source]

# File kwartz/translator.rb, line 96
    def translate(stmt_list=[])
      @sb = ''
      @sb << @header if @header
      stmt_list.each do |stmt|
        stmt.accept(self)
      end
      @sb << @footer if @footer
      return @sb
    end

[Source]

# File kwartz/translator.rb, line 127
    def translate_native_expr(expr)
      assert unless expr.is_a?(NativeExpression)
      flag_escape = expr.escape?
      flag_escape = @escape if flag_escape == nil
      if flag_escape
        @sb << @escape_l << expr.code << @escape_r     # ex. <%=h expr.code %>
      else
        @sb << @expr_l << expr.code << @expr_r         # ex. <%= expr.code %>
      end
    end

[Source]

# File kwartz/translator.rb, line 107
    def translate_native_stmt(stmt)
      @sb << @stmt_l << stmt.code << @stmt_r   # ex. <% stmt.code %>
      @sb << @nl unless stmt.no_newline
    end

[Source]

# File kwartz/translator.rb, line 113
    def translate_print_stmt(stmt)
      stmt.args.each do |arg|
        #arg.accept(self)
        if arg.is_a?(String)
          translate_string(arg)
        elsif arg.is_a?(NativeExpression)
          translate_native_expr(arg)
        else
          assert
        end
      end
    end

[Source]

# File kwartz/translator.rb, line 139
    def translate_string(str)
      @sb << str
    end

[Validate]