Class: Docbook::Output::Pipeline

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

Overview

Composable data processing pipeline for DocBook XML.

Orchestrates steps that parse XML, generate TOC, numbering, index, transform to DocbookMirror JSON, attach metadata, generate lists, and resolve image paths. Returns a complete guide hash ready for consumption by any Format class.

Steps are pluggable — pass a custom step list to add, remove, or reorder processing stages without modifying this class.

Usage: guide = Pipeline.new(xml_path: "book.xml").process

# Custom pipeline with extra step steps = Pipeline::DEFAULT_STEPS.dup.insert(5, MyCustomStep) guide = Pipeline.new(xml_path: "book.xml", steps: steps).process

Constant Summary collapse

DEFAULT_STEPS =
[
  PipelineSteps::ParseXml,
  PipelineSteps::AssignIds,
  PipelineSteps::GenerateToc,
  PipelineSteps::GenerateNumbering,
  PipelineSteps::GenerateIndex,
  PipelineSteps::TransformMirror,
  PipelineSteps::AttachMetadata,
  PipelineSteps::GenerateLists,
  PipelineSteps::ResolveImages,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_path:, steps: DEFAULT_STEPS, image_search_dirs: [], image_strategy: :data_url, sort_glossary: false, title: "DocBook") ⇒ Pipeline

Returns a new instance of Pipeline.

Parameters:

  • xml_path (String)

    path to the DocBook XML file

  • steps (Array<Class>) (defaults to: DEFAULT_STEPS)

    pipeline step classes (must implement #call(guide, context))

  • image_search_dirs (Array<String>) (defaults to: [])

    directories to search for images

  • image_strategy (Symbol) (defaults to: :data_url)

    :file_url, :data_url, or :relative

  • sort_glossary (Boolean) (defaults to: false)

    sort glossary entries alphabetically

  • title (String) (defaults to: "DocBook")

    fallback title for the document



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/docbook/output/pipeline.rb', line 46

def initialize(xml_path:, steps: DEFAULT_STEPS, image_search_dirs: [],
               image_strategy: :data_url, sort_glossary: false, title: "DocBook")
  @steps = steps
  @context = PipelineContext.new(
    xml_path: xml_path,
    image_search_dirs: Array(image_search_dirs),
    image_strategy: image_strategy,
    sort_glossary: sort_glossary,
    title: title,
    parsed: nil,
  )
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



38
39
40
# File 'lib/docbook/output/pipeline.rb', line 38

def context
  @context
end

#stepsObject (readonly)

Returns the value of attribute steps.



38
39
40
# File 'lib/docbook/output/pipeline.rb', line 38

def steps
  @steps
end

Instance Method Details

#processHash

Run the pipeline and return the complete guide hash.

Returns:

  • (Hash)

    the guide data with toc, index, meta, content



61
62
63
64
65
66
# File 'lib/docbook/output/pipeline.rb', line 61

def process
  guide = {}
  @steps.reduce(guide) do |current_guide, step_class|
    step_class.new.call(current_guide, @context)
  end
end