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:



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

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

Instance Method Details

#add_expr_debug(src, code) ⇒ Object



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

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

#add_expr_escaped(src, code) ⇒ Object



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

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

#add_expr_literal(src, code) ⇒ Object



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

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

#add_postamble(src) ⇒ Object



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

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

#add_preamble(src) ⇒ Object



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

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

#add_stmt(src, code) ⇒ Object



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

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

#add_text(src, text) ⇒ Object



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

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

#escape_text(text) ⇒ Object



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

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

#init_generator(properties = {}) ⇒ Object



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

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