Module: Dimples::Frontable

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

Instance Method Summary collapse

Instance Method Details

#read_with_yaml(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dimples/frontable.rb', line 3

def read_with_yaml(path)
  if File.extname(path) == '.yml'
    contents = ''
     = YAML.load_file(path)
  else
    contents = File.read(path)
    matches = contents.match(/^(-{3}\n.*?\n?)^(-{3}*$\n?)/m)

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

  if 
    .each_pair do |key, value|
      self.class.send(:attr_accessor, key.to_sym) unless self.respond_to?(key.to_sym)
      self.send("#{key}=", value)
    end
  end

  contents
end