Method: HtmlTemplate#initialize
- Defined in:
- lib/html/template.rb
#initialize(text = nil, filename: nil, strict: config.strict?, loop_vars: config.loop_vars?) ⇒ HtmlTemplate
Returns a new instance of HtmlTemplate.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/html/template.rb', line 139 def initialize( text=nil, filename: nil, strict: config.strict?, loop_vars: config.loop_vars? ) if text.nil? ## try to read file (by filename) text = File.open( filename, 'r:utf-8' ) { |f| f.read } end ## options @strict = strict @loop_vars = loop_vars ## todo/fix: add filename to ERB too (for better error reporting) @text, @errors, @names = convert( text ) ## note: keep a copy of the converted template text if @errors.size > 0 puts "!! ERROR - #{@errors.size} conversion / syntax error(s):" pp @errors raise if strict? ## todo - find a good Error - StandardError - why? why not? end @template = ERB.new( @text, nil, '%<>' ) end |