Class: Coradoc::CoreModel::Block
- Includes:
- ChildrenContent
- Defined in:
- lib/coradoc/core_model/block.rb
Overview
Generic block model
Represents all block-level elements in a format-neutral way. Each block has a ‘block_semantic_type` symbol (e.g., :source_code, :quote, :example) that captures its semantic meaning without tying it to any specific format’s syntax.
Direct Known Subclasses
AnnotationBlock, ExampleBlock, ListingBlock, LiteralBlock, OpenBlock, PassBlock, QuoteBlock, SidebarBlock, SourceBlock, VerseBlock
Instance Attribute Summary collapse
-
#block_semantic_type ⇒ String?
The semantic type of the block (e.g., ‘source_code’, ‘quote’, ‘example’, ‘paragraph’).
-
#content ⇒ String?
The block’s text content (simple string) For mixed content with inline elements, use children instead.
-
#delimiter_length ⇒ Integer
Number of delimiter characters (default: 4).
-
#delimiter_type ⇒ String?
DEPRECATED — use block_semantic_type.
-
#element_type ⇒ String?
The structural role of the block (e.g., ‘paragraph’, ‘block’).
-
#language ⇒ String?
Language identifier for source code blocks.
-
#lines ⇒ Array<String>?
Individual lines of content.
Attributes inherited from Base
#element_attributes, #id, #metadata_entries, #title
Class Method Summary collapse
-
.semantic_type ⇒ Object
Class-level semantic type — overridden by each typed subclass.
Instance Method Summary collapse
-
#resolve_semantic_type ⇒ Object
Resolve the semantic type from this block instance.
Methods included from ChildrenContent
#children=, #flat_text, included, #initialize, #renderable_content, #to_hash
Methods inherited from Base
#accept, #attr, #metadata, #semantically_equivalent?, #set_attr, #set_metadata
Instance Attribute Details
#block_semantic_type ⇒ String?
Returns the semantic type of the block (e.g., ‘source_code’, ‘quote’, ‘example’, ‘paragraph’).
83 |
# File 'lib/coradoc/core_model/block.rb', line 83 attribute :block_semantic_type, :string |
#content ⇒ String?
Returns the block’s text content (simple string) For mixed content with inline elements, use children instead.
102 |
# File 'lib/coradoc/core_model/block.rb', line 102 attribute :content, :string |
#delimiter_length ⇒ Integer
Returns number of delimiter characters (default: 4).
97 |
# File 'lib/coradoc/core_model/block.rb', line 97 attribute :delimiter_length, :integer, default: -> { 4 } |
#delimiter_type ⇒ String?
Returns DEPRECATED — use block_semantic_type. Retained for backward compatibility during migration.
93 |
# File 'lib/coradoc/core_model/block.rb', line 93 attribute :delimiter_type, :string |
#element_type ⇒ String?
Returns the structural role of the block (e.g., ‘paragraph’, ‘block’).
88 |
# File 'lib/coradoc/core_model/block.rb', line 88 attribute :element_type, :string |
#language ⇒ String?
Returns language identifier for source code blocks.
110 |
# File 'lib/coradoc/core_model/block.rb', line 110 attribute :language, :string |
#lines ⇒ Array<String>?
Returns individual lines of content.
106 |
# File 'lib/coradoc/core_model/block.rb', line 106 attribute :lines, :string, collection: true |
Class Method Details
.semantic_type ⇒ Object
Class-level semantic type — overridden by each typed subclass. Returns nil for the generic Block base class.
64 65 66 |
# File 'lib/coradoc/core_model/block.rb', line 64 def semantic_type nil end |
Instance Method Details
#resolve_semantic_type ⇒ Object
Resolve the semantic type from this block instance. Checks class-level semantic_type first (typed subclasses), then the block_semantic_type attribute, then element_type, then delimiter_type fallback.
73 74 75 76 77 78 |
# File 'lib/coradoc/core_model/block.rb', line 73 def resolve_semantic_type self.class.semantic_type || (block_semantic_type&.to_sym) || resolve_semantic_from_element_type || resolve_semantic_from_delimiter end |