Module: Coradoc::AsciiDoc::Transform::ElementTransformers::AdmonitionStyles

Defined in:
lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb

Overview

Admonition style registry. Single source of truth for “which positional attribute names map to an admonition block.”

Built-in AsciiDoc admonition styles are always recognized. Callers can register additional styles (e.g. DANGER, SAFETY) without modifying dispatch code — the registry is consulted by every block-form transformer that needs to decide between an admonition and the block’s native type.

Constant Summary collapse

BUILTIN =
%w[note tip warning caution important editor todo].freeze

Class Method Summary collapse

Class Method Details

.admonition?(style) ⇒ Boolean

True if style (case-insensitive) is a known admonition style.

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 22

def admonition?(style)
  return false if style.nil?

  name = style.to_s.downcase
  BUILTIN.include?(name) || custom.include?(name)
end

.all_stylesObject

All registered style names (BUILTIN + custom), lowercased.



40
41
42
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 40

def all_styles
  (BUILTIN + custom).freeze
end

.canonicalize(style) ⇒ Object

Canonical uppercase form for style, or nil if unknown. Single source of truth for the canonical casing used in CoreModel::AnnotationBlock#annotation_type and AsciiDoc round-trip output.



33
34
35
36
37
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 33

def canonicalize(style)
  return nil unless admonition?(style)

  style.to_s.upcase
end

.customObject



57
58
59
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 57

def custom
  @custom.dup
end

.register(style) ⇒ Object

Register an additional admonition style. Open for extension.



45
46
47
48
49
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 45

def register(style)
  name = style.to_s.downcase
  @custom << name unless @custom.include?(name) || BUILTIN.include?(name)
  self
end

.reset!Object

Reset custom registrations. Intended for specs.



52
53
54
55
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 52

def reset!
  @custom = []
  self
end