Class: Metanorma::Cli::SiteGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/cli/site_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}, compile_options = {}) ⇒ SiteGenerator

Returns a new instance of SiteGenerator.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/metanorma/cli/site_generator.rb', line 8

def initialize(source, options = {}, compile_options = {})
  @collection_queue = []
  @source = find_realpath(source)
  @site_path = options.fetch(
    :output_dir, Commands::Site::SITE_OUTPUT_DIRNAME
  ).to_s
  @asset_folder = options.fetch(:asset_folder, "documents").to_s
  @collection_name = options.fetch(:collection_name, "documents.xml")

  @manifest_file = find_realpath(options.fetch(:config, default_config))
  @template_dir = options.fetch(:template_dir, template_data("path"))
  @stylesheet = options.fetch(:stylesheet, template_data("stylesheet"))

  @compile_options = compile_options
  ensure_site_asset_directory!
end

Class Method Details

.generate(source, options = {}, compile_options = {}) ⇒ Object



25
26
27
# File 'lib/metanorma/cli/site_generator.rb', line 25

def self.generate(source, options = {}, compile_options = {})
  new(source, options, compile_options).generate
end

Instance Method Details

#generateObject



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

def generate
  site_directory = asset_directory.join("..")

  fatals = select_source_files.map { |source| compile(source) }
    .flatten
    .compact

  raise Errors::FatalCompilationError, fatals unless fatals.empty?

  Dir.chdir(site_directory) do
    build_collection_file(collection_name)
    convert_to_html_page(collection_name, "index.html")
  end

  dequeue_jobs
end