Class: Templette::Generator
- Inherits:
-
Object
- Object
- Templette::Generator
- Defined in:
- lib/templette/generator.rb
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize(out_dir = 'out', resources_dir = 'resources') ⇒ Generator
constructor
A new instance of Generator.
- #output_location ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(out_dir = 'out', resources_dir = 'resources') ⇒ Generator
Returns a new instance of Generator.
3 4 5 6 7 |
# File 'lib/templette/generator.rb', line 3 def initialize(out_dir = 'out', resources_dir = 'resources') @out_dir = out_dir @resources_dir = resources_dir @errors = [] end |
Instance Method Details
#clean ⇒ Object
39 40 41 |
# File 'lib/templette/generator.rb', line 39 def clean FileUtils.rm_rf(@out_dir) if File.exists?(@out_dir) end |
#output_location ⇒ Object
35 36 37 |
# File 'lib/templette/generator.rb', line 35 def output_location @out_dir + Templette::config[:site_root] end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/templette/generator.rb', line 9 def run FileUtils.mkdir_p(output_location) unless File.exists?(output_location) pages = Page.find_all puts "Generating site in: #{output_location}; contains #{pages.size} pages" pages.each do |page| puts "Generating page #{page.name} using template #{page.template.name}" begin page.generate(output_location) rescue Templette::TempletteError => e @errors.push(e) end end if File.exists?(@resources_dir) puts "Copying resources from #{@resources_dir} to #{output_location}" FileUtils.cp_r("#{@resources_dir}/.", output_location) end if @errors.empty? puts "Site generation complete!" else puts "SITE GENERATED WITH ERRORS!" @errors.each { |e| puts e. } end end |