Class: Kwartz::RubyTranslator
- Inherits:
-
BaseTranslator
- Object
- Translator
- BaseTranslator
- Kwartz::RubyTranslator
- Includes:
- RubyExpressionParser
- 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 included from RubyExpressionParser
#parse_expr_str, #parse_expr_str!
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.
191 192 193 194 195 196 197 |
# File 'lib/kwartz/binding/ruby.rb', line 191 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
214 215 216 217 |
# File 'lib/kwartz/binding/ruby.rb', line 214 def translate(stmt_list) stmt_list2 = optimize_print_stmts(stmt_list) return super(stmt_list2) end |
#translate_string(str) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/kwartz/binding/ruby.rb', line 200 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 |