Module: Template
- Defined in:
- lib/doorway/template.rb
Instance Method Summary collapse
- #asset(name) ⇒ Object
- #compile_template(template, vars) ⇒ Object
- #create_from_template(file, template, vars = {}) ⇒ Object
- #temp_from_template(template, vars = {}) ⇒ Object
- #write_file(file, contents) ⇒ Object
Instance Method Details
#asset(name) ⇒ Object
5 6 7 |
# File 'lib/doorway/template.rb', line 5 def asset(name) File.("../../../assets/#{name}", __FILE__) end |
#compile_template(template, vars) ⇒ Object
9 10 11 12 13 |
# File 'lib/doorway/template.rb', line 9 def compile_template(template, vars) contents = File.read asset(template) struct = ErbBinding.new(vars) ERB.new(contents).result(struct.send(:get_binding)) end |
#create_from_template(file, template, vars = {}) ⇒ Object
15 16 17 |
# File 'lib/doorway/template.rb', line 15 def create_from_template(file, template, vars={}) write_file file, compile_template(template, vars) end |
#temp_from_template(template, vars = {}) ⇒ Object
19 20 21 22 |
# File 'lib/doorway/template.rb', line 19 def temp_from_template(template, vars={}) tmp = Tempfile.new("doorway") tmp.write compile_template(template, vars) end |
#write_file(file, contents) ⇒ Object
24 25 26 |
# File 'lib/doorway/template.rb', line 24 def write_file(file, contents) File.open(file, 'w+') { |f| f.write contents } end |