Module: Dimples::Frontable

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

Overview

Adds the ability to read frontmatter from a file.

Instance Method Summary collapse

Instance Method Details

#read_with_front_matter(path) ⇒ Object



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

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

  if (matches = contents.match(/^(-{3}\n.*?\n?)^(-{3}*$\n?)/m))
     = Hashie.symbolize_keys(YAML.safe_load(matches[1]))
    contents = matches.post_match.strip
  else
     = {}
  end

  [contents, ]
end