Class: Docbook::Output::PipelineSteps::AttachMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/docbook/output/pipeline_steps/attach_metadata.rb

Overview

Step 6: Attach TOC, numbering, index, and metadata to the guide hash.

Assembles the final guide structure from intermediate data produced by earlier steps (toc_sections_raw, numbering, index_data, stats).

Instance Method Summary collapse

Instance Method Details

#call(guide, context) ⇒ Object



11
12
13
14
15
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
# File 'lib/docbook/output/pipeline_steps/attach_metadata.rb', line 11

def call(guide, context)
  # Merge TOC sections + numbering into toc structure
  toc_sections = guide.delete("toc_sections_raw") || []
  numbering_hash = guide.delete("numbering") || {}
  guide["toc"] = {
    "sections" => toc_sections,
    "numbering" => numbering_hash,
  }

  # Attach index
  if guide.key?("index_data")
    guide["index"] =
      guide.delete("index_data")
  end

  # Generate and attach metadata
  stats = Services::DocumentStats.new(context.parsed).generate
  guide["meta"] = {
    "title" => stats["title"] || context.title,
    "subtitle" => stats["subtitle"],
    "author" => stats["author"],
    "pubdate" => stats["pubdate"],
    "releaseinfo" => stats["releaseinfo"],
    "copyright" => stats["copyright"],
    "cover" => stats["cover"],
    "root_element" => stats["root_element"],
  }.compact

  guide
end