Module: Dimples::Frontable

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

Overview

A mixin class that handles reading and parsing front matter from a file.

Instance Method Summary collapse

Instance Method Details

#apply_metadata(metadata) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/dimples/frontable.rb', line 20

def ()
  .each_pair do |key, value|
    unless respond_to?(key.to_sym)
      self.class.send(:attr_accessor, key.to_sym)
    end

    send("#{key}=", value)
  end
end

#read_with_front_matter(path) ⇒ Object



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

def read_with_front_matter(path)
  contents = File.read(path)
  matches = contents.match(/^(-{3}\n.*?\n?)^(-{3}*$\n?)/m)

  if matches
     = YAML.safe_load(matches[1])
    contents = matches.post_match.strip

    () if 
  end

  contents
end