Method: Tenjin::Template#initialize

Defined in:
lib/tenjin.rb

#initialize(filename = nil, options = {}) ⇒ Template

initializer of Template class.

options:

:escapefunc

function name to escape value (default ‘escape’)

:preamble

preamble such as “_buf = ”” (default nil)

:postamble

postamble such as “_buf.to_s” (default nil)



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/tenjin.rb', line 509

def initialize(filename=nil, options={})
  if filename.is_a?(Hash)
    options = filename
    filename = nil
  end
  @filename   = filename
  @escapefunc = options[:escapefunc] || ESCAPE_FUNCTION
  @preamble   = options[:preamble]  == true ? "_buf = #{init_buf_expr()}; " : options[:preamble]
  @postamble  = options[:postamble] == true ? finish_buf_expr() : options[:postamble]
  @input      = options[:input]
  @trace      = options[:trace] || TRACE
  @args       = nil  # or array of argument names
  if @input
    convert(@input, filename)
  elsif filename
    convert_file(filename)
  end
end