Class: Blueprint::Generator::Base::TemplateRendering
- Inherits:
-
Object
- Object
- Blueprint::Generator::Base::TemplateRendering
- Defined in:
- lib/blueprint/generator/base/template_rendering.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, config) ⇒ TemplateRendering
constructor
A new instance of TemplateRendering.
- #render(template_file) ⇒ Object
- #save(from, to) ⇒ Object
Constructor Details
#initialize(name, config) ⇒ TemplateRendering
9 10 11 12 |
# File 'lib/blueprint/generator/base/template_rendering.rb', line 9 def initialize(name, config) @name = name @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/blueprint/generator/base/template_rendering.rb', line 7 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/blueprint/generator/base/template_rendering.rb', line 7 def name @name end |
Instance Method Details
#render(template_file) ⇒ Object
14 15 16 17 |
# File 'lib/blueprint/generator/base/template_rendering.rb', line 14 def render(template_file) template = File.open(template_file).read ERB.new(template, 0, '%<>').result(binding) end |
#save(from, to) ⇒ Object
19 20 21 22 23 |
# File 'lib/blueprint/generator/base/template_rendering.rb', line 19 def save(from, to) File.open(to, 'w+') do |f| f.write(render(from)) end end |