Class: Shipyard::Builder
- Inherits:
-
Object
- Object
- Shipyard::Builder
- Defined in:
- lib/shipyard/builder.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(manifest_file, table) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
8 9 10 |
# File 'lib/shipyard/builder.rb', line 8 def db @db end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
7 8 9 |
# File 'lib/shipyard/builder.rb', line 7 def table @table end |
Instance Method Details
#generate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shipyard/builder.rb', line 15 def generate templates = Dir['*.erb'] templates.each do |template| abort "No destination mapped for template '#{template}'" unless !!@manifest.destination_for(template) end puts "Rendering to output directory #{@manifest.output_dir}" templates.each do |filename| open(filename) do |file| # pass in the context object and render the template template = ERB.new(file.read) template.filename = filename code = template.result(@context.get_binding) # write the rendered file to the associated destination dst = @manifest.destination_for(filename) output_file = File.join(@manifest.output_dir, dst) File.makedirs(File.dirname(output_file)) open(output_file, 'w') do |f| puts "\t#{filename} => #{output_file}" f.write(code) end end end end |