Class: Ligarb::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/ligarb/builder.rb

Defined Under Namespace

Classes: StructNode

Instance Method Summary collapse

Constructor Details

#initialize(config_path, parent_data: nil) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
# File 'lib/ligarb/builder.rb', line 11

def initialize(config_path, parent_data: nil)
  @config = Config.new(config_path, parent_data: parent_data)
  @config_path = File.expand_path(config_path)
end

Instance Method Details

#buildObject



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
# File 'lib/ligarb/builder.rb', line 16

def build
  if @config.translations_hub?
    build_multilang
    return
  end

  structure = load_structure

  all_chapters = collect_all_chapters(structure)
  resolve_cross_references(all_chapters)
  assign_relative_paths(all_chapters) if @config.repository

  assets = AssetManager.new(@config.output_path)
  assets.detect(all_chapters)
  assets.provision!

  index_entries = all_chapters.flat_map { |ch|
    ch.index_entries.map { |e|
      e.class.new(term: e.term, display_text: e.display_text,
                  chapter_slug: e.chapter_slug, anchor_id: e.anchor_id)
    }
  }

  bibliography = resolve_citations!(all_chapters)

  html = Template.new.render(config: @config, chapters: all_chapters,
                             structure: structure, assets: assets,
                             index_entries: index_entries,
                             bibliography: bibliography,
                             github_review: github_review_data(@config))

  FileUtils.mkdir_p(@config.output_path)
  output_file = File.join(@config.output_path, "index.html")
  File.write(output_file, html)

  copy_images

  puts "Built #{output_file}"
  puts "  #{all_chapters.size} chapter(s)"
end