Class: Dimples::FrontMatter

Inherits:
Object
  • Object
show all
Defined in:
lib/dimples/frontmatter.rb

Overview

Adds the ability to parse front matter from a file.

Constant Summary collapse

FRONT_MATTER_PATTERN =
/^(-{3}\n.*?\n?)^(-{3}*$\n?)/m.freeze

Class Method Summary collapse

Class Method Details

.parse(contents) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dimples/frontmatter.rb', line 8

def self.parse(contents)
  if (matches = contents.match(FRONT_MATTER_PATTERN))
     = Hashie.symbolize_keys(YAML.safe_load(matches[1]))
    contents = matches.post_match.strip
  else
     = {}
  end

  [contents, ]
end