Module: Dimples::Frontable

Included in:
Page, Template
Defined in:
lib/dimples/frontable.rb

Overview

Adds the ability to read frontmatter from a file.

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#read_with_front_matter(path) ⇒ Object



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

def read_with_front_matter(path)
  contents = File.read(path)

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

  [contents, ]
end