Module: Coradoc::CoreModel::Builder::ListBuilder Private
- Included in:
- Coradoc::CoreModel::Builder
- Defined in:
- lib/coradoc/core_model/builder/list_builder.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
List building module for Builder
Contains methods for building list elements from AST structures.
Instance Method Summary collapse
-
#build_definition_content(ast) ⇒ Object
private
Build definition content from terms and definition.
-
#build_definition_item(ast) ⇒ Object
private
Build definition list item.
-
#build_definition_list(ast) ⇒ Object
private
Build definition list.
-
#build_item_children(attached_ast) ⇒ Object
private
Build item children (attached blocks).
-
#build_list_block(ast) ⇒ Object
private
Build list block.
-
#build_list_items(items_ast) ⇒ Object
private
Build list items.
-
#build_nested_list(nested_ast) ⇒ Object
private
Build nested list.
-
#build_ordered_list(ast) ⇒ Object
private
Build ordered list.
-
#build_unordered_list(ast) ⇒ Object
private
Build unordered list.
-
#extract_item_content(ast) ⇒ Object
private
Extract item content from various formats.
Instance Method Details
#build_definition_content(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build definition content from terms and definition
81 82 83 84 85 86 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 81 def build_definition_content(ast) terms = Array(ast[:terms]).join(', ') definition = ast[:definition] || ast[:contents] "#{terms}: #{definition}" end |
#build_definition_item(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build definition list item
70 71 72 73 74 75 76 77 78 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 70 def build_definition_item(ast) item_ast = ast[:definition_list_item] || ast ListItem.new( marker: '::', content: build_definition_content(item_ast), children: [] ) end |
#build_definition_list(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build definition list
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 49 def build_definition_list(ast) items = Array(ast[:definition_list]).map do |item| build_definition_item(item) end ListBlock.new( marker_type: 'definition', marker_level: 1, items: items, attributes: build_attributes_private(ast[:attribute_list]) ) end |
#build_item_children(attached_ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build item children (attached blocks)
104 105 106 107 108 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 104 def build_item_children(attached_ast) return [] unless attached_ast Array(attached_ast).map { |child| build_element(child) }.compact end |
#build_list_block(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build list block
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 13 def build_list_block(ast) ListBlock.new( marker_type: detect_marker_type(ast), marker_level: detect_marker_level(ast), items: build_list_items(ast[:items] || ast[:list_items]), title: ast[:title], id: ast[:id], attributes: build_attributes_private(ast[:attribute_list]) ) end |
#build_list_items(items_ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build list items
63 64 65 66 67 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 63 def build_list_items(items_ast) return [] unless items_ast Array(items_ast).map { |item| build_list_item(item) } end |
#build_nested_list(nested_ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build nested list
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 89 def build_nested_list(nested_ast) return nil unless nested_ast if nested_ast.is_a?(Array) ListBlock.new( marker_type: 'asterisk', marker_level: 2, items: nested_ast.map { |item| build_list_item(item) } ) else build_element(nested_ast) end end |
#build_ordered_list(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build ordered list
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 37 def build_ordered_list(ast) items = Array(ast[:ordered]).map { |item| build_list_item(item) } ListBlock.new( marker_type: 'numbered', marker_level: 1, items: items, attributes: build_attributes_private(ast[:attribute_list]) ) end |
#build_unordered_list(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build unordered list
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 25 def build_unordered_list(ast) items = Array(ast[:unordered]).map { |item| build_list_item(item) } ListBlock.new( marker_type: 'asterisk', marker_level: 1, items: items, attributes: build_attributes_private(ast[:attribute_list]) ) end |
#extract_item_content(ast) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Extract item content from various formats
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/coradoc/core_model/builder/list_builder.rb', line 111 def extract_item_content(ast) if ast[:text] case ast[:text] when String ast[:text] when Array ast[:text].map(&:to_s).join else ast[:text].to_s end elsif ast[:content] ast[:content].to_s else '' end end |