Class: Coradoc::CoreModel::AttributeReferenceResolver
- Inherits:
-
Object
- Object
- Coradoc::CoreModel::AttributeReferenceResolver
- Defined in:
- lib/coradoc/core_model/attribute_reference_resolver.rb
Overview
Walks a CoreModel tree and resolves InlineElement nodes whose format_type is ‘attribute_reference’ against a Metadata store.
AsciiDoc ‘foo` references round-trip as InlineElement with format_type: ’attribute_reference’ and target: ‘foo’. After the document is parsed and its attributes are known, this visitor rewrites those nodes in place to TextContent carrying the value. Unresolved references are left untouched so they survive serialisation back to the source format.
The visitor never mutates its input tree; it returns a new tree sharing unchanged subtrees. InlineElement#with_content already produces non-mutating copies for inline content; the same pattern is used here at the block level via ‘replace_children`.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ AttributeReferenceResolver
constructor
A new instance of AttributeReferenceResolver.
- #visit(node) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ AttributeReferenceResolver
Returns a new instance of AttributeReferenceResolver.
26 27 28 |
# File 'lib/coradoc/core_model/attribute_reference_resolver.rb', line 26 def initialize(attributes) @attributes = attributes || Metadata.new end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
20 21 22 |
# File 'lib/coradoc/core_model/attribute_reference_resolver.rb', line 20 def attributes @attributes end |
Class Method Details
Instance Method Details
#visit(node) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/coradoc/core_model/attribute_reference_resolver.rb', line 30 def visit(node) return node.map { |child| visit(child) } if node.is_a?(Array) return node unless node.is_a?(Base) visit_typed(node) end |