Class: Coradoc::Mirror::ReverseBuilder::Base
- Inherits:
-
Object
- Object
- Coradoc::Mirror::ReverseBuilder::Base
- Defined in:
- lib/coradoc/mirror/reverse_builder/base.rb
Overview
Base class for all reverse builders. Subclasses register one or more Mirror type strings via ‘registers` and implement `#build`. Shared helpers (build_content, extract_text, apply_mark, …) are delegated to the context (a MirrorToCoreModel instance), keeping each builder focused on the per-type mapping only (DRY).
Direct Known Subclasses
Admonition, BiblioEntry, Bibliography, Blockquote, BulletList, Caption, CodeBlock, DefinitionList, Document, Example, Figure, FootnoteEntry, FootnoteMarker, Footnotes, Frontmatter, GenericBlock, Header, HorizontalRule, Image, Include, InlineText, ListItem, LiteralBlock, OpenBlock, OrderedList, Paragraph, PassBlock, Preamble, RawInline, Section, Sections, Sidebar, SoftBreak, StemBlock, Table, TableBody, TableCell, TableHead, TableRow, Text, Toc, TocEntry, Verse
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
-
.registers(*types) ⇒ Object
DSL: declare which Mirror type strings this builder handles.
Instance Method Summary collapse
- #apply_mark(inner, mark) ⇒ Object
- #build(_node) ⇒ Object
-
#build_content(node) ⇒ Object
Shared helpers — all delegate to the context (DRY).
- #build_inline_children(node) ⇒ Object
- #build_node(node) ⇒ Object
- #extract_text(node) ⇒ Object
-
#initialize(context) ⇒ Base
constructor
A new instance of Base.
- #inline_content(element) ⇒ Object
Constructor Details
#initialize(context) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 14 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 12 def context @context end |
Class Method Details
.registers(*types) ⇒ Object
DSL: declare which Mirror type strings this builder handles. Multiple strings per builder are allowed (e.g. all JS SECTION_TYPES route to the same SectionElement builder).
35 36 37 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 35 def registers(*types) types.each { |t| ReverseBuilder.register(t, self) } end |
Instance Method Details
#apply_mark(inner, mark) ⇒ Object
28 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 28 def apply_mark(inner, mark) = context.apply_mark(inner, mark) |
#build(_node) ⇒ Object
18 19 20 21 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 18 def build(_node) raise NotImplementedError, "#{self.class} must implement #build(node)" end |
#build_content(node) ⇒ Object
Shared helpers — all delegate to the context (DRY).
24 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 24 def build_content(node) = context.build_content(node) |
#build_inline_children(node) ⇒ Object
25 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 25 def build_inline_children(node) = context.build_inline_children(node) |
#build_node(node) ⇒ Object
26 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 26 def build_node(node) = context.build_node(node) |
#extract_text(node) ⇒ Object
27 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 27 def extract_text(node) = context.extract_text(node) |
#inline_content(element) ⇒ Object
29 |
# File 'lib/coradoc/mirror/reverse_builder/base.rb', line 29 def inline_content(element) = context.inline_content(element) |