Class: Boxes::Template
Overview
Representations of Packer templates.
Defined Under Namespace
Classes: ERBContext
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(env, name) ⇒ Boxes::Template
constructor
Load a template with a given name.
-
#render(args) ⇒ String
Render the template.
Constructor Details
#initialize(env, name) ⇒ Boxes::Template
Load a template with a given name.
14 15 16 17 18 19 20 21 22 |
# File 'lib/boxes/template.rb', line 14 def initialize(env, name) fail(TemplateNotFoundError) unless env.available_templates.include?(name) @name = name @template = '' File.open(Boxes.config.working_dir + "templates/#{name}.erb") do |f| @template << f.read end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/boxes/template.rb', line 6 def name @name end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
6 7 8 |
# File 'lib/boxes/template.rb', line 6 def template @template end |
Instance Method Details
#render(args) ⇒ String
Render the template.
29 30 31 |
# File 'lib/boxes/template.rb', line 29 def render(args) ERB.new(template, nil, '-').result(ERBContext.new(args).get_binding) end |