Module: Edison::YAMLFrontMatter
- Defined in:
- lib/edison.rb
Class Method Summary collapse
Class Method Details
.read(fname) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/edison.rb', line 13 def self.read(fname) contents = File.read(fname).strip if contents =~ /\A---/ _, yaml, body = contents.split("---", 3) yaml = YAML.load(yaml) body ||= "" body.strip! if yaml.include? "body" raise Exception, "YAML Front Matter can't contain a 'body' key. Put it after the front matter." end {"body" => body}.merge(yaml) else {"body" => contents} end end |