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

.customObject



42
43
44
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 42

def custom
  @custom.dup
end

.register(style) ⇒ Object

Register an additional admonition style. Open for extension.



30
31
32
33
34
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 30

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.



37
38
39
40
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 37

def reset!
  @custom = []
  self
end