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 =
Generic
[admonition](capitalized as ADMONITION bycanonicalize) is the spec-defined generic admonition style. It is rarely used directly but exists in the AsciiDoc spec; treating it as a real admonition prevents it from collapsing to an ExampleBlock when applied to a delimited block. %w[note tip warning caution important editor todo admonition].freeze
Class Method Summary collapse
-
.admonition?(style) ⇒ Boolean
True if
style(case-insensitive) is a known admonition style. -
.all_styles ⇒ Object
All registered style names (BUILTIN + custom), lowercased.
-
.canonicalize(style) ⇒ Object
Canonical uppercase form for
style, or nil if unknown. - .custom ⇒ Object
-
.register(style) ⇒ Object
Register an additional admonition style.
-
.reset! ⇒ Object
Reset custom registrations.
Class Method Details
.admonition?(style) ⇒ Boolean
True if style (case-insensitive) is a known admonition style.
27 28 29 30 31 32 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 27 def admonition?(style) return false if style.nil? name = style.to_s.downcase BUILTIN.include?(name) || custom.include?(name) end |
.all_styles ⇒ Object
All registered style names (BUILTIN + custom), lowercased.
45 46 47 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 45 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.
38 39 40 41 42 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 38 def canonicalize(style) return nil unless admonition?(style) style.to_s.upcase end |
.custom ⇒ Object
62 63 64 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 62 def custom @custom.dup end |
.register(style) ⇒ Object
Register an additional admonition style. Open for extension.
50 51 52 53 54 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 50 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.
57 58 59 60 |
# File 'lib/coradoc/asciidoc/transform/element_transformers/admonition_styles.rb', line 57 def reset! @custom = [] self end |