Class: Coradoc::AsciiDoc::Model::Image::Core

Inherits:
Base
  • Object
show all
Includes:
Anchorable
Defined in:
lib/coradoc/asciidoc/model/image/core.rb,
lib/coradoc/asciidoc/model/image/core/attribute_list.rb

Overview

Base class for image elements in AsciiDoc documents.

Images can be block-level (standalone paragraphs) or inline (within text). This base class provides common functionality for both types.

Typed promotion of attribute-list slots

Semantically meaningful image attributes (alt, role, width, height, link) are declared as typed lutaml-model fields on Core itself — not as validators on a generic bag. The class-level Core.promoted_positional and Core.promoted_named methods are the single source of truth for which slots get lifted into typed fields and in what order; subclasses override them to reflect syntax differences (e.g. inline images treat the 2nd positional as role, block images do not).

The lift itself is performed by AttributeExtractor, a pure function over (AttributeList, target_class) → (extracted_hash, residual_list). Anything not promoted stays in attributes for round-trip fidelity.

Direct Known Subclasses

BlockImage, BlockImage, InlineImage

Defined Under Namespace

Classes: AttributeList

Instance Attribute Summary

Attributes inherited from Base

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Anchorable

#default_anchor, #gen_anchor, included, #initialize

Methods inherited from Base

#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_h, visit, #visit

Class Method Details

Named attribute-list keys that this image class promotes to typed fields. The same set applies to both inline and block images.

Returns:

  • (Array<Symbol>)


65
66
67
# File 'lib/coradoc/asciidoc/model/image/core.rb', line 65

def self.promoted_named
  %i[width height link role]
end

Positional attribute-list slots that this image class promotes to typed fields, in order. Subclasses override to reflect their syntax. Index 0 → alt for all image kinds; index 1 → role for inline images only.

Returns:

  • (Array<Symbol>)


58
59
60
# File 'lib/coradoc/asciidoc/model/image/core.rb', line 58

def self.promoted_positional
  %i[alt]
end

Instance Method Details

#to_adocString

Custom to_adoc implementation that uses ElementRegistry directly to avoid recursion issues with image serialization.

Returns:

  • (String)

    AsciiDoc representation of this image



73
74
75
76
# File 'lib/coradoc/asciidoc/model/image/core.rb', line 73

def to_adoc
  serializer_class = Coradoc::AsciiDoc::Serializer::ElementRegistry.lookup(self.class)
  serializer_class.new.to_adoc(self)
end