Class: Usmu::SiteGenerator
- Inherits:
-
Object
- Object
- Usmu::SiteGenerator
- Defined in:
- lib/usmu/site_generator.rb
Overview
This is the class that brings everything together to generate a new website.
Instance Attribute Summary collapse
-
#files ⇒ Array<Usmu::StaticFile>
readonly
A list of static files from the source folder.
-
#layouts ⇒ Array<Usmu::Layout>
readonly
A list of layouts available in this website.
-
#pages ⇒ Array<Usmu::Page>
readonly
A list of pages from the source folder.
-
#renderables ⇒ Array<Usmu::StaticFile>
readonly
Returns a list of renderable files from the source folder.
Instance Method Summary collapse
-
#generate
Generate the website according to the configuration given.
-
#initialize(configuration) ⇒ SiteGenerator
constructor
A new instance of SiteGenerator.
Constructor Details
#initialize(configuration) ⇒ SiteGenerator
Returns a new instance of SiteGenerator.
10 11 12 13 |
# File 'lib/usmu/site_generator.rb', line 10 def initialize(configuration) @log = Logging.logger[self] @configuration = configuration end |
Instance Attribute Details
#files ⇒ Array<Usmu::StaticFile> (readonly)
Returns a list of static files from the source folder.
49 50 51 |
# File 'lib/usmu/site_generator.rb', line 49 def files renderables.select {|r| r.class.name == 'Usmu::StaticFile'} end |
#layouts ⇒ Array<Usmu::Layout> (readonly)
Returns a list of layouts available in this website.
17 18 19 |
# File 'lib/usmu/site_generator.rb', line 17 def layouts @configuration.layouts_files.map {|l| Usmu::Layout.new(@configuration, l) } end |
#pages ⇒ Array<Usmu::Page> (readonly)
Returns a list of pages from the source folder. This is any file in the source folder which is not static.
43 44 45 |
# File 'lib/usmu/site_generator.rb', line 43 def pages renderables.select {|r| r.class.name != 'Usmu::StaticFile'} end |
#renderables ⇒ Array<Usmu::StaticFile> (readonly)
Returns a list of renderable files from the source folder.
The only guarantee made for individual files is that they will conform to the interface defined by Usmu::StaticFile and thus be renderable, however most files will be one of the subclasses of that class.
30 31 32 33 34 35 36 37 38 |
# File 'lib/usmu/site_generator.rb', line 30 def renderables @configuration.source_files.map do |filename| if Usmu::Layout.is_valid_file? 'source', filename Usmu::Page.new(@configuration, filename) else Usmu::StaticFile.new(@configuration, filename) end end end |
Instance Method Details
#generate
This method returns an undefined value.
Generate the website according to the configuration given.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/usmu/site_generator.rb', line 56 def generate @log.info("Source: #{@configuration.source_path}") @log.info("Destination: #{@configuration.destination_path}") renderables.each do |page| @log.success("creating #{page.output_filename}...") file = File.join(@configuration.destination_path, page.output_filename) directory = File.dirname(file) unless File.directory?(directory) FileUtils.mkdir_p(directory) end File.write file, page.render FileUtils.touch file, :mtime => File.stat(page.input_path).mtime end nil end |