Class: Coradoc::CoreModel::InlineElement

Inherits:
Base
  • Object
show all
Includes:
ChildrenContent
Defined in:
lib/coradoc/core_model/inline_element.rb,
lib/coradoc/core_model/inline_element.rb

Overview

Wire-name table: bidirectional string ↔ class index. Single source of truth for serialization names and runtime dispatch. Reopened onto InlineElement so the subclasses above are defined first.

Constant Summary collapse

FORMAT_TYPE_CLASS_MAP =
{
  'bold' => BoldElement,
  'italic' => ItalicElement,
  'monospace' => MonospaceElement,
  'underline' => UnderlineElement,
  'strikethrough' => StrikethroughElement,
  'subscript' => SubscriptElement,
  'superscript' => SuperscriptElement,
  'highlight' => HighlightElement,
  'link' => LinkElement,
  'xref' => CrossReferenceElement,
  'stem' => StemElement,
  'footnote' => FootnoteElement,
  'hard_line_break' => HardLineBreakElement,
  'text' => TextElement,
  'span' => SpanElement,
  'term' => TermElement,
  'line_break' => LineBreakElement
}.freeze
FORMAT_TYPES =
FORMAT_TYPE_CLASS_MAP.keys.freeze

Instance Attribute Summary

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ChildrenContent

#flat_text, included, #renderable_content

Methods included from HasChildren

#has_children?

Methods inherited from Base

#accept, #attr, #body_content?, build, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata, #whitespace_only?

Class Method Details

.format_typeObject



15
16
17
# File 'lib/coradoc/core_model/inline_element.rb', line 15

def self.format_type
  nil
end

.format_type_class(type) ⇒ Object



19
20
21
# File 'lib/coradoc/core_model/inline_element.rb', line 19

def self.format_type_class(type)
  FORMAT_TYPE_CLASS_MAP[type] || InlineElement
end

Instance Method Details

Polymorphic classification used by LinkRewriter::Visitor. Returns :link / :xref when this node carries a rewrite-able target, nil otherwise. Generic InlineElement instances defer to their resolved format_type; typed subclasses override with a literal. Keeps the visitor free of class-keyed case/when (OCP).



39
40
41
42
43
44
# File 'lib/coradoc/core_model/inline_element.rb', line 39

def link_kind
  case resolve_format_type
  when 'link' then :link
  when 'xref' then :xref
  end
end

#resolve_format_typeObject



23
24
25
# File 'lib/coradoc/core_model/inline_element.rb', line 23

def resolve_format_type
  self.class.format_type || format_type
end

#with_content(new_content) ⇒ Object

Return a duplicate of this element with its content replaced. Used by InlineContent.strip_edges (and other edge-cleanup callers) so that mutations never leak through the public API.



30
31
32
# File 'lib/coradoc/core_model/inline_element.rb', line 30

def with_content(new_content)
  dup.tap { |copy| copy.content = new_content }
end