Module: Coradoc::AsciiDoc::Builder::ElementBuilder

Included in:
Coradoc::AsciiDoc::Builder
Defined in:
lib/coradoc/asciidoc/builder/element_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_attribute(ast) ⇒ Object



126
127
128
129
130
131
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 126

def build_attribute(ast)
  Coradoc::CoreModel::ElementAttribute.new(
    name: ast[:key],
    value: ast[:value]
  )
end

#build_bibliography_entry(ast) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 109

def build_bibliography_entry(ast)
  bib_ast = ast[:bibliography_entry] || ast['bibliography_entry'] || ast

  Coradoc::CoreModel::BibliographyEntry.new(
    anchor_name: bib_ast[:anchor_name] || bib_ast['anchor_name'],
    document_id: bib_ast[:document_id] || bib_ast['document_id'],
    ref_text: bib_ast[:ref_text] || bib_ast['ref_text']
  )
end

#build_comment_block(ast) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 66

def build_comment_block(ast)
  comment_ast = ast[:comment_block] || ast['comment_block'] || ast

  Coradoc::CoreModel::CommentBlock.new(
    content: comment_ast[:comment_text] || comment_ast['comment_text']
  )
end

#build_comment_line(ast) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 58

def build_comment_line(ast)
  comment_ast = ast[:comment_line] || ast['comment_line'] || ast

  Coradoc::CoreModel::CommentBlock.new(
    content: comment_ast[:comment_text] || comment_ast['comment_text']
  )
end

#build_generic_element(ast) ⇒ Object



119
120
121
122
123
124
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 119

def build_generic_element(ast)
  Coradoc::CoreModel::Block.new(
    block_semantic_type: 'unknown',
    content: ast.to_s
  )
end

#build_header(ast) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 7

def build_header(ast)
  header_ast = ast[:header] || ast

  Coradoc::CoreModel::HeaderElement.new(
    title: extract_text_content(header_ast[:title]),
    id: header_ast[:id]
  )
end

#build_include(ast) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 74

def build_include(ast)
  include_ast = ast[:include] || ast['include'] || ast

  Coradoc::CoreModel::Block.new(
    block_semantic_type: 'include',
    content: include_ast[:path] || include_ast['path']
  )
end

#build_line_break(ast) ⇒ Object



51
52
53
54
55
56
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 51

def build_line_break(ast)
  Coradoc::CoreModel::Block.new(
    block_semantic_type: 'line_break',
    content: ast[:line_break] || ast['line_break']
  )
end

#build_section(ast) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 16

def build_section(ast)
  section_ast = ast[:section] || ast

  Coradoc::CoreModel::SectionElement.new(
    title: extract_text_content(section_ast[:title]),
    id: section_ast[:id],
    level: extract_level(section_ast),
    children: build_section_contents(section_ast[:contents]) +
              build_subsections(section_ast[:sections]),
    attributes: (section_ast[:attribute_list])
  )
end

#build_section_contents(contents_ast) ⇒ Object



39
40
41
42
43
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 39

def build_section_contents(contents_ast)
  return [] unless contents_ast

  Array(contents_ast).map { |content| build_element(content) }.compact
end

#build_section_metadata(attribute_list) ⇒ Object

Coerces the AST attribute_list (hash / string / nil) through the normalizer, then delegates to Transform::AttributeListToMetadata for the typed Model::AttributeList -> CoreModel::Metadata step. Single source of truth lives in the transform layer (DRY/MECE).



33
34
35
36
37
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 33

def (attribute_list)
  list = Coradoc::AsciiDoc::Transformer::AttributeListNormalizer
         .coerce(attribute_list)
  Coradoc::AsciiDoc::Transform::AttributeListToMetadata.call(list)
end

#build_subsections(sections_ast) ⇒ Object



45
46
47
48
49
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 45

def build_subsections(sections_ast)
  return [] unless sections_ast

  Array(sections_ast).map { |section| build_element(section) }.compact
end

#build_table(ast) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 83

def build_table(ast)
  table_ast = ast[:table] || ast['table'] || ast

  Coradoc::CoreModel::Table.new(
    title: table_ast[:title] || table_ast['title'],
    id: table_ast[:id] || table_ast['id'],
    rows: table_ast[:rows] || table_ast['rows'] || []
  )
end

#build_tag(ast) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 100

def build_tag(ast)
  tag_ast = ast[:tag] || ast['tag'] || ast

  Coradoc::CoreModel::Block.new(
    block_semantic_type: 'tag',
    content: tag_ast[:name] || tag_ast['name']
  )
end

#build_unparsed(ast) ⇒ Object



93
94
95
96
97
98
# File 'lib/coradoc/asciidoc/builder/element_builder.rb', line 93

def build_unparsed(ast)
  Coradoc::CoreModel::Block.new(
    block_semantic_type: 'unparsed',
    content: (ast[:unparsed] || ast['unparsed']).to_s
  )
end