Module: Ottogen::FrontMatter
- Defined in:
- lib/ottogen/front_matter.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- OPENERS =
["---\n", "---\r\n"].freeze
Class Method Summary collapse
Class Method Details
.split(raw, path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ottogen/front_matter.rb', line 11 def self.split(raw, path) return [{}, raw] unless OPENERS.any? { |opener| raw.start_with?(opener) } lines = raw.lines closing = lines[1..].index { |line| line.chomp == '---' } raise Error, "unclosed front matter in #{path}" if closing.nil? yaml_text = lines[1..closing].join body = (lines[(closing + 2)..] || []).join [parse_yaml(yaml_text, path), body] end |