Class: Usmu::SiteGenerator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ SiteGenerator

Returns a new instance of SiteGenerator.

Parameters:



11
12
13
14
# File 'lib/usmu/site_generator.rb', line 11

def initialize(configuration)
  @log = Logging.logger[self]
  @configuration = configuration
end

Instance Attribute Details

#layoutsArray<Usmu::Layout> (readonly)

Returns a list of layouts available in this website.

Returns:

  • (Array<Usmu::Layout>)

    a list of layouts available in this website.



18
19
20
# File 'lib/usmu/site_generator.rb', line 18

def layouts
  @configuration.layouts_files.map {|l| Template::Layout.new(@configuration, l, @configuration..(l)) }
end

#renderablesArray<Usmu::Template::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::Template::StaticFile and thus be renderable, however most files will be one of the subclasses of that class.

Returns:

See Also:

  • Usmu::StaticFile


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/usmu/site_generator.rb', line 31

def renderables
  @renderables ||= begin
    rs = @configuration.source_files.map do |filename|
       = @configuration..(filename)
      if Template::Layout.is_valid_file?('source', filename) && (!['static'])
        Template::Page.new(@configuration, filename, )
      else
        Template::StaticFile.new(@configuration, filename, )
      end
    end

    Usmu.plugins.alter(:renderables, rs, self)
  end
end

Instance Method Details

#collectionsUsmu::Collections

Returns an interface for interacting with collections defined in this site.

Returns:



61
62
63
# File 'lib/usmu/site_generator.rb', line 61

def collections
  @collections ||= Collections.new(self)
end

#generatevoid

This method returns an undefined value.

Generate the website according to the configuration given.



49
50
51
52
53
54
55
56
# File 'lib/usmu/site_generator.rb', line 49

def generate
  @log.info("Source: #{@configuration.source_path}")
  @log.info("Destination: #{@configuration.destination_path}")
  @log.info('')

  renderables.each &method(:generate_page)
  nil
end

#generate_page(page) ⇒ void (private)

Helper function to generate a page

Parameters:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/usmu/site_generator.rb', line 76

def generate_page(page)
  output_filename = page.output_filename
  @log.success("creating #{output_filename}...")
  @log.debug("Rendering #{output_filename} from #{page.name}")
  file = File.join(@configuration.destination_path, output_filename)
  directory = File.dirname(file)

  unless File.directory?(directory)
    FileUtils.mkdir_p(directory)
  end

  File.write file, page.render

  FileUtils.touch file, mtime: page.mtime
  nil
end

#refreshvoid

Refresh information about this site.



66
67
68
69
# File 'lib/usmu/site_generator.rb', line 66

def refresh
  collections.refresh
  nil
end