Module: Elzar::Template
- Defined in:
- lib/elzar/template.rb
Class Attribute Summary collapse
-
.source_directory ⇒ Object
Returns the value of attribute source_directory.
Class Method Summary collapse
- .create_template_binding(ivars) ⇒ Object
- .generate(file, dest, ivars = {}) ⇒ Object
- .generate_string(file, ivars = {}) ⇒ Object
Class Attribute Details
.source_directory ⇒ Object
Returns the value of attribute source_directory.
5 6 7 |
# File 'lib/elzar/template.rb', line 5 def source_directory @source_directory end |
Class Method Details
.create_template_binding(ivars) ⇒ Object
18 19 20 21 22 |
# File 'lib/elzar/template.rb', line 18 def self.create_template_binding(ivars) obj = Object.new ivars.each {|name, val| obj.instance_variable_set("@#{name}", val) } obj.instance_eval { binding } end |
.generate(file, dest, ivars = {}) ⇒ Object
8 9 10 11 |
# File 'lib/elzar/template.rb', line 8 def self.generate(file, dest, ivars={}) str = generate_string(file, ivars) File.open("#{dest}/#{file}", 'w+') {|f| f.write str } end |
.generate_string(file, ivars = {}) ⇒ Object
13 14 15 16 |
# File 'lib/elzar/template.rb', line 13 def self.generate_string(file, ivars={}) file = source_directory + "/#{file}.erb" ERB.new(File.read(file)).result(create_template_binding(ivars)) end |