Module: Erubis::PerlGenerator

Includes:
Generator
Included in:
Eperl, Erubis::PI::Eperl
Defined in:
lib/erubis/engine/eperl.rb

Instance Attribute Summary

Attributes included from Generator

#escapefunc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generator

#escaped_expr

Class Method Details

.supported_propertiesObject

:nodoc:



16
17
18
19
20
# File 'lib/erubis/engine/eperl.rb', line 16

def self.supported_properties()  # :nodoc:
  return [
          [:func, 'print', "function name"],
          ]
end

Instance Method Details

#add_expr_debug(src, code) ⇒ Object



49
50
51
52
53
# File 'lib/erubis/engine/eperl.rb', line 49

def add_expr_debug(src, code)
  code.strip!
  s = code.gsub(/\'/, "\\'")
  src << @func << "('*** debug: #{code}=', #{code}, \"\\n\");"
end

#add_expr_escaped(src, code) ⇒ Object



45
46
47
# File 'lib/erubis/engine/eperl.rb', line 45

def add_expr_escaped(src, code)
  add_expr_literal(src, escaped_expr(code))
end

#add_expr_literal(src, code) ⇒ Object



40
41
42
43
# File 'lib/erubis/engine/eperl.rb', line 40

def add_expr_literal(src, code)
  code.strip!
  src << @func << "(" << code << "); "
end

#add_postamble(src) ⇒ Object



59
60
61
# File 'lib/erubis/engine/eperl.rb', line 59

def add_postamble(src)
  src << "\n" unless src[-1] == ?\n
end

#add_preamble(src) ⇒ Object



28
29
30
# File 'lib/erubis/engine/eperl.rb', line 28

def add_preamble(src)
  src << "use HTML::Entities; ";
end

#add_stmt(src, code) ⇒ Object



55
56
57
# File 'lib/erubis/engine/eperl.rb', line 55

def add_stmt(src, code)
  src << code
end

#add_text(src, text) ⇒ Object



36
37
38
# File 'lib/erubis/engine/eperl.rb', line 36

def add_text(src, text)
  src << @func << "('" << escape_text(text) << "'); " unless text.empty?
end

#escape_text(text) ⇒ Object



32
33
34
# File 'lib/erubis/engine/eperl.rb', line 32

def escape_text(text)
  return text.gsub!(/['\\]/, '\\\\\&') || text
end

#init_generator(properties = {}) ⇒ Object



22
23
24
25
26
# File 'lib/erubis/engine/eperl.rb', line 22

def init_generator(properties={})
  super
  @escapefunc ||= 'encode_entities'
  @func = properties[:func] || 'print'
end