Class: Kwartz::RubyTranslator
- Inherits:
-
BaseTranslator
- Object
- Translator
- BaseTranslator
- Kwartz::RubyTranslator
- Defined in:
- lib/kwartz/binding/ruby.rb
Overview
translator for eRuby
Instance Attribute Summary
Attributes inherited from BaseTranslator
Instance Method Summary collapse
-
#initialize(properties = {}) ⇒ RubyTranslator
constructor
A new instance of RubyTranslator.
- #translate(stmt_list) ⇒ Object
- #translate_string(str) ⇒ Object
Methods inherited from BaseTranslator
#translate_native_expr, #translate_native_stmt, #translate_print_stmt
Methods inherited from Translator
get_class, register_class, #translate_native_expr, #translate_native_stmt, #translate_print_stmt
Constructor Details
#initialize(properties = {}) ⇒ RubyTranslator
Returns a new instance of RubyTranslator.
159 160 161 162 163 164 165 |
# File 'lib/kwartz/binding/ruby.rb', line 159 def initialize(properties={}) escapefunc = properties[:escapefunc] || 'ERB::Util.h' marks = ['', '', '_buf << (', ').to_s; ', "_buf << #{escapefunc}(", '); '] super(marks, properties) @header = '_buf = ""; ' unless @header == false @footer = '; _buf' + @nl unless @footer == false end |
Instance Method Details
#translate(stmt_list) ⇒ Object
182 183 184 185 |
# File 'lib/kwartz/binding/ruby.rb', line 182 def translate(stmt_list) stmt_list2 = optimize_print_stmts(stmt_list) return super(stmt_list2) end |
#translate_string(str) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/kwartz/binding/ruby.rb', line 168 def translate_string(str) return if str.nil? || str.empty? #str.gsub!(/['\\]/, '\\\\\&') #@sb << "_buf << '#{str}'; " str.gsub!(/["\\]/, '\\\\\&') if str[-1] == ?\n str.chop! @sb << "_buf << \"#{str}\\n\";" << @nl else @sb << "_buf << \"#{str}\"; " end end |