Class: Blueprint::Generator::Base::TemplateRendering

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprint/generator/base/template_rendering.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/blueprint/generator/base/template_rendering.rb', line 7

def config
  @config
end

#nameObject (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