Class: Metanorma::Cli::SiteGenerator

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

Constant Summary collapse

DEFAULT_RELATON_COLLECTION_INDEX =
"documents.xml"
DEFAULT_ASSET_FOLDER =
"documents"
DEFAULT_SITE_INDEX =
"index.html"
DEFAULT_CONFIG_FILE =
"metanorma.yml"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metanorma/cli/site_generator.rb', line 16

def initialize(source_path, options = {}, compile_options = {})
  @collection_queue = []
  @source_path = find_realpath(source_path)
  @site_path = Pathname.new(
    options.fetch(:output_dir, Commands::Site::SITE_OUTPUT_DIRNAME),
  )

  @asset_folder = options.fetch(:asset_folder, DEFAULT_ASSET_FOLDER).to_s
  @relaton_collection_index = options.fetch(
    :collection_name,
    DEFAULT_RELATON_COLLECTION_INDEX,
  )

  @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"))
  @output_filename_template = options.fetch(
    :output_filename_template,
    template_data("output_filename"),
  )

  # Determine base path for stylesheet & template files
  # If the file path is relative, it is relative to the directory
  # containing the site manifest file.
  # If site manifest file is not provided, then it is relative to the
  # current directory.
  @base_path = if manifest_file.nil?
                 Pathname.pwd
               else
                 Pathname.new(manifest_file).parent
               end

  @compile_options = compile_options

  # Resolve the output formats to generate: CLI `--extensions` (a
  # comma-separated string in compile_options) takes precedence over the
  # manifest `extensions:` list; empty means "all formats the flavor
  # supports" (the historical default).  Remove it from @compile_options
  # so it is injected explicitly and not double-handled downstream.
  @extensions = resolve_extensions
  @compile_options.delete(:extensions)
end

Class Method Details

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

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



60
61
62
# File 'lib/metanorma/cli/site_generator.rb', line 60

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

Instance Method Details

#generate!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/metanorma/cli/site_generator.rb', line 64

def generate!
  ensure_site_asset_directory!

  # compile individual document files
  compile_files!(select_source_files)

  site_directory = asset_directory.parent

  # actually compile collection file(s)
  compile_collections!

  Dir.chdir(site_directory) do
    build_collection_file!(relaton_collection_index)
    convert_to_html_page!(relaton_collection_index, DEFAULT_SITE_INDEX)
  end
end