Class: Kwartz::PIErubisTranslator

Inherits:
BaseTranslator show all
Includes:
RubyExpressionParser
Defined in:
lib/kwartz/binding/pierubis.rb

Overview

translator for Erubis

Constant Summary collapse

PIERUBIS_EMBED_PATTERNS =
[
  '<?rb ', ' ?>',      # statement
  '@!{',   '}@',       # expression
  '@{',    '}@',       # escaped expression
]

Instance Attribute Summary

Attributes inherited from BaseTranslator

#escape, #footer, #header

Instance Method Summary collapse

Methods included from RubyExpressionParser

#parse_expr_str, #parse_expr_str!

Methods inherited from BaseTranslator

#translate, #translate_native_stmt, #translate_print_stmt, #translate_string

Methods inherited from Translator

get_class, register_class, #translate, #translate_native_stmt, #translate_print_stmt, #translate_string

Constructor Details

#initialize(properties = {}) ⇒ PIErubisTranslator

Returns a new instance of PIErubisTranslator.



37
38
39
40
# File 'lib/kwartz/binding/pierubis.rb', line 37

def initialize(properties={})
  super(PIERUBIS_EMBED_PATTERNS, properties)
  #@escape = true if @escape == nil
end

Instance Method Details

#translate_native_expr(expr) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/kwartz/binding/pierubis.rb', line 43

def translate_native_expr(expr)
  assert unless expr.is_a?(NativeExpression)
  if expr.code.include?(?}) || expr.code.include?(?>)
    @expr_l, @expr_r, @escape_l, @escape_r = '<%=', '%>', '<%==', '%>'
  else
    @expr_l, @expr_r, @escape_l, @escape_r = '@!{', '}@', '@{', '}@'
  end
  super(expr)
end