Module: Pikuri::Bundle::Frontmatter
- Defined in:
- lib/pikuri/bundle/frontmatter.rb
Overview
Splits a bundle file into its YAML frontmatter and its body.
Frontmatter.split(File.read(path), path: path)
# => [{"description" => "Weekly work log"}, "# Weekly work log\n…"]
A file with no --- block splits as [nil, body] — the caller decides
whether that is a skipped file or an ordinary one, and the two bundle
surfaces answer differently. Malformed YAML degrades to [{}, body]
with a warning rather than raising: a frontmatter typo should cost the
keys, not the file.
Class Method Summary collapse
Class Method Details
.split(content, path:) ⇒ Array(Hash{String=>Object}, String), Array(nil, String)
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pikuri/bundle/frontmatter.rb', line 27 def split(content, path:) normalized = content.gsub(/\r\n?/, "\n") return [nil, normalized] unless normalized.start_with?("---\n") end_marker = normalized.index("\n---", 4) return [nil, normalized] unless end_marker body = normalized[(end_marker + 4)..].to_s.sub(/\A\n/, '') [parse(normalized[4...end_marker], path: path), body] end |