Class: Kwartz::BaseTranslator
- Inherits:
-
Translator
- Object
- Translator
- Kwartz::BaseTranslator
- Defined in:
- lib/kwartz/translator.rb
Overview
concrete class for visitor pattern
see ErbTranslator, PhpTranslator, JstlTranslator, and so on for detail.
Direct Known Subclasses
EperlTranslator, ErubisTranslator, ErubyTranslator, JstlTranslator, PIErubisTranslator, PhpTranslator, RailsTranslator, RubyTranslator
Instance Attribute Summary collapse
-
#escape ⇒ Object
Returns the value of attribute escape.
-
#footer ⇒ Object
Returns the value of attribute footer.
-
#header ⇒ Object
Returns the value of attribute header.
Instance Method Summary collapse
-
#initialize(marks = [], properties = {}) ⇒ BaseTranslator
constructor
A new instance of BaseTranslator.
- #translate(stmt_list) ⇒ Object
- #translate_native_expr(expr) ⇒ Object
- #translate_native_stmt(stmt) ⇒ Object
- #translate_print_stmt(stmt) ⇒ Object
- #translate_string(str) ⇒ Object
Methods inherited from Translator
Constructor Details
#initialize(marks = [], properties = {}) ⇒ BaseTranslator
Returns a new instance of BaseTranslator.
83 84 85 86 87 88 89 90 |
# File 'lib/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 |
Instance Attribute Details
#escape ⇒ Object
Returns the value of attribute escape.
93 94 95 |
# File 'lib/kwartz/translator.rb', line 93 def escape @escape end |
#footer ⇒ Object
Returns the value of attribute footer.
93 94 95 |
# File 'lib/kwartz/translator.rb', line 93 def @footer end |
#header ⇒ Object
Returns the value of attribute header.
93 94 95 |
# File 'lib/kwartz/translator.rb', line 93 def header @header end |
Instance Method Details
#translate(stmt_list) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/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 |
#translate_native_expr(expr) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/kwartz/translator.rb', line 128 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 add_escaped_expr(expr.code) else add_plain_expr(expr.code) end end |
#translate_native_stmt(stmt) ⇒ Object
107 108 109 110 |
# File 'lib/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 |
#translate_print_stmt(stmt) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/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) (arg) elsif arg.is_a?(NativeExpression) translate_native_expr(arg) else assert end end end |
#translate_string(str) ⇒ Object
140 141 142 |
# File 'lib/kwartz/translator.rb', line 140 def translate_string(str) @sb << str end |