Class: Coradoc::CoreModel::FrontmatterBlock

Inherits:
Block
  • Object
show all
Defined in:
lib/coradoc/core_model/frontmatter.rb,
lib/coradoc/core_model/frontmatter/codec.rb,
lib/coradoc/core_model/frontmatter/text_splitter.rb,
lib/coradoc/core_model/frontmatter/field_transform.rb,
lib/coradoc/core_model/frontmatter/schema_resolver.rb

Overview

First-class block representing YAML frontmatter attached to a document.

Frontmatter is modeled as a Block (not a side-attribute on DocumentElement) so it flows through the standard block pipeline: parsers produce it, transformers dispatch on its class, serializers emit it. No special-casing anywhere.

The data hash stores the entire parsed YAML frontmatter (minus $schema, which is promoted to the schema attribute). Using a hash — rather than a typed value tree — lets coradoc accept any frontmatter shape without code changes. Type handling is delegated to Ruby’s native YAML/JSON, which already preserve Date, Integer, Float, Boolean, nil, Array, and Hash correctly for YAML round-trips.

The $schema key, if present in source YAML, is promoted to the schema attribute (single source of truth — DRY); SchemaResolver reads it to find validators.

Defined Under Namespace

Modules: Codec, FieldTransform, SchemaResolver, TextSplitter

Instance Attribute Summary

Attributes inherited from Block

#block_semantic_type, #content, #delimiter_type, #language, #lines

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#element_type, #resolve_semantic_type

Methods included from ChildrenContent

#flat_text, included, #renderable_content

Methods inherited from Base

#accept, #attr, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata

Class Method Details

.element_type_nameObject



28
29
30
# File 'lib/coradoc/core_model/frontmatter.rb', line 28

def self.element_type_name
  'frontmatter'
end

.semantic_typeObject



24
25
26
# File 'lib/coradoc/core_model/frontmatter.rb', line 24

def self.semantic_type
  :frontmatter
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/coradoc/core_model/frontmatter.rb', line 49

def empty?
  schema.nil? && (data.nil? || data.empty?)
end

#entry(key) ⇒ Object

Convenience accessor — read a single entry by key.



41
42
43
# File 'lib/coradoc/core_model/frontmatter.rb', line 41

def entry(key)
  data[key.to_s]
end

#has_entry?(key) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/coradoc/core_model/frontmatter.rb', line 45

def has_entry?(key)
  data.key?(key.to_s)
end