Class: Lono::Template
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, block, options = {}) ⇒ Template
constructor
A new instance of Template.
- #partial(path) ⇒ Object
- #source(path) ⇒ Object
- #user_data(path) ⇒ Object
- #variables(vars = {}) ⇒ Object
Constructor Details
#initialize(name, block, options = {}) ⇒ Template
Returns a new instance of Template.
58 59 60 61 62 63 |
# File 'lib/lono/dsl.rb', line 58 def initialize(name, block, ={}) @name = name @block = block @options = @options[:project_root] ||= '.' end |
Instance Method Details
#build ⇒ Object
65 66 67 68 69 |
# File 'lib/lono/dsl.rb', line 65 def build instance_eval(&@block) template = IO.read(@source) ERB.new(template).result(binding) end |
#partial(path) ⇒ Object
81 82 83 84 85 |
# File 'lib/lono/dsl.rb', line 81 def partial(path) path = "#{@options[:project_root]}/templates/partial/#{path}" template = IO.read(path) ERB.new(template).result(binding) end |
#source(path) ⇒ Object
71 72 73 |
# File 'lib/lono/dsl.rb', line 71 def source(path) @source = "#{@options[:project_root]}/templates/#{path}" end |
#user_data(path) ⇒ Object
87 88 89 90 91 |
# File 'lib/lono/dsl.rb', line 87 def user_data(path) path = "#{@options[:project_root]}/templates/user_data/#{path}" template = IO.read(path) ERB.new(template).result(binding).split("\n").collect {|l| "#{l}\n"}.to_json end |
#variables(vars = {}) ⇒ Object
75 76 77 78 79 |
# File 'lib/lono/dsl.rb', line 75 def variables(vars={}) vars.each do |var,value| instance_variable_set("@#{var}", value) end end |