Class: Docbook::Mirror::Transformer

Inherits:
Object
  • Object
show all
Includes:
Services::ElementIdHelper
Defined in:
lib/docbook/mirror/transformer.rb

Instance Method Summary collapse

Methods included from Services::ElementIdHelper

#element_id, #refentry_id, #resolve_refentry_title

Constructor Details

#initialize(sort_glossary: false) ⇒ Transformer

Returns a new instance of Transformer.



10
11
12
13
14
15
# File 'lib/docbook/mirror/transformer.rb', line 10

def initialize(sort_glossary: false)
  @xml_id_map = {}
  @footnote_counter = 0
  @footnotes = []
  @sort_glossary = sort_glossary
end

Instance Method Details

#from_docbook(docbook_doc) ⇒ Object

Entry point: Convert DocBook document to DocbookMirror



18
19
20
21
22
23
# File 'lib/docbook/mirror/transformer.rb', line 18

def from_docbook(docbook_doc)
  @xml_id_map = build_xml_id_map(docbook_doc)
  @footnote_counter = 0
  @footnotes = []
  document_node(docbook_doc)
end

#to_docbook(mirror_node) ⇒ Object

=========================================

Round-trip: DocbookMirror → DocBook



1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
# File 'lib/docbook/mirror/transformer.rb', line 1400

def to_docbook(mirror_node)
  case mirror_node.type
  when "doc"
    docbook_document(mirror_node)
  when "paragraph"
    docbook_paragraph(mirror_node)
  when "text"
    docbook_text(mirror_node)
  when "code_block"
    docbook_code_block(mirror_node)
  when "blockquote"
    docbook_blockquote(mirror_node)
  when "bullet_list"
    docbook_itemized_list(mirror_node)
  when "ordered_list"
    docbook_ordered_list(mirror_node)
  when "list_item"
    docbook_list_item(mirror_node)
  when "dl"
    docbook_variable_list(mirror_node)
  when "definition_term"
    docbook_definition_term(mirror_node)
  when "definition_description"
    docbook_definition_description(mirror_node)
  when "admonition"
    docbook_admonition(mirror_node)
  when "chapter"
    docbook_chapter(mirror_node)
  when "section"
    docbook_section(mirror_node)
  when "part"
    docbook_part(mirror_node)
  when "appendix"
    docbook_appendix(mirror_node)
  when "reference"
    docbook_reference(mirror_node)
  when "image"
    docbook_image(mirror_node)
  else
    raise Error, "Unknown node type: #{mirror_node.type}"
  end
end