Class: Coradoc::CoreModel::ListBlock
- Defined in:
- lib/coradoc/core_model/list_block.rb
Overview
Represents a list block with proper nesting support
Handles all list types:
-
Unordered lists
-
Ordered lists
-
Description lists
Lists can contain nested lists at multiple levels, with each level tracked through marker_level.
Instance Attribute Summary collapse
-
#items ⇒ Array<ListItem>
Collection of list items.
-
#marker_level ⇒ Integer
Nesting level of the list (default: 1).
-
#marker_type ⇒ String?
Type of list marker (e.g., ‘unordered’, ‘ordered’, ‘definition’).
-
#start ⇒ Integer?
Starting number for ordered lists.
Attributes inherited from Base
#element_attributes, #id, #metadata_entries, #title
Instance Method Summary collapse
-
#add_item(marker: self.marker_type == 'ordered' ? '.' : '*') ⇒ Object
Append a new ListItem, built via ListItem.build.
Methods inherited from Base
#accept, #attr, #body_content?, build, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata, #whitespace_only?
Instance Attribute Details
#items ⇒ Array<ListItem>
Returns collection of list items.
109 |
# File 'lib/coradoc/core_model/list_block.rb', line 109 attribute :items, ListItem, collection: true |
#marker_level ⇒ Integer
Returns nesting level of the list (default: 1).
101 |
# File 'lib/coradoc/core_model/list_block.rb', line 101 attribute :marker_level, :integer, default: -> { 1 } |
#marker_type ⇒ String?
Returns type of list marker (e.g., ‘unordered’, ‘ordered’, ‘definition’).
97 |
# File 'lib/coradoc/core_model/list_block.rb', line 97 attribute :marker_type, :string |
#start ⇒ Integer?
Returns starting number for ordered lists.
105 |
# File 'lib/coradoc/core_model/list_block.rb', line 105 attribute :start, :integer |
Instance Method Details
#add_item(marker: self.marker_type == 'ordered' ? '.' : '*') ⇒ Object
Append a new ListItem, built via ListItem.build. The block (if given) is yielded the new item so callers can chain add_text / add_link on it inline:
ListBlock.build do |ul|
children.each { |c| ul.add_item { |li| li.add_link(c[:slug], text: c[:title]) } }
end
Returns self for chaining at the list level.
122 123 124 125 126 |
# File 'lib/coradoc/core_model/list_block.rb', line 122 def add_item(marker: self.marker_type == 'ordered' ? '.' : '*') item = ListItem.build(marker: marker) { |li| yield li if block_given? } self.items = Array(items) + [item] self end |