Class: Ace::Support::Items::Atoms::FrontmatterSerializer
- Inherits:
-
Object
- Object
- Ace::Support::Items::Atoms::FrontmatterSerializer
- Defined in:
- lib/ace/support/items/atoms/frontmatter_serializer.rb
Overview
Serializes frontmatter hashes to YAML block strings with ‘—` delimiters. Preserves inline-array style (`tags: [ux, design]`) and quotes YAML-ambiguous values.
Constant Summary collapse
- YAML_AMBIGUOUS =
/\A(true|false|yes|no|on|off|null|~|-?\d+(\.\d+)?([eE][+-]?\d+)?)\z/i
Class Method Summary collapse
-
.rebuild(frontmatter, body) ⇒ String
Rebuild a full document from frontmatter and body.
-
.serialize(frontmatter) ⇒ String
Serialize frontmatter hash to YAML block string.
Class Method Details
.rebuild(frontmatter, body) ⇒ String
Rebuild a full document from frontmatter and body
29 30 31 |
# File 'lib/ace/support/items/atoms/frontmatter_serializer.rb', line 29 def self.rebuild(frontmatter, body) "#{serialize(frontmatter)}\n\n#{body}" end |
.serialize(frontmatter) ⇒ String
Serialize frontmatter hash to YAML block string
16 17 18 19 20 21 22 23 |
# File 'lib/ace/support/items/atoms/frontmatter_serializer.rb', line 16 def self.serialize(frontmatter) lines = ["---"] frontmatter.each do |key, value| serialize_entry(lines, key, value, indent: 0) end lines << "---" lines.join("\n") end |