Method: Tap::Templater#initialize
- Defined in:
- lib/tap/templater.rb
#initialize(template, attributes = {}) ⇒ Templater
Initialized a new Templater. An ERB or String may be provided as the template. If a String is provided, it will be used to initialize an ERB with a trim_mode of “<>”.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/tap/templater.rb', line 145 def initialize(template, attributes={}) @template = case template when ERB # matching w/wo the coding effectively checks @src # across ruby versions (encoding appears in 1.9) if template.instance_variable_get(:@src) !~ /^(#coding:US-ASCII\n)?_erbout =/ raise ArgumentError, "Templater does not work with ERB templates where eoutvar != '_erbout'" end template when String then ERB.new(template, nil, "<>") else raise ArgumentError, "cannot convert #{template.class} into an ERB template" end src = @template.instance_variable_get(:@src) @template.instance_variable_set(:@src, "self." + src) super(attributes) end |