Class: Jekyll::FridgePage

Inherits:
Page
  • Object
show all
Defined in:
lib/jekyll-fridge/fridge_page.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, content, config) ⇒ FridgePage

Returns a new instance of FridgePage.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jekyll-fridge/fridge_page.rb', line 3

def initialize(site, base, dir, content, config)
  @site = site
  @base = base
  @dir = dir
  @name = "index.html"

  self.process(@name)
  if content.attrs.has_key?(:template)
    self.read_yaml_from_string(content.template)
  else
    self.read_yaml(File.join(base, '_layouts'), config['layout'])
  end

  self.data[config['type']] = Jekyll::Fridge::Model.new(content)
  self.data['title'] = content.title
end

Instance Method Details

#read_yaml_from_string(str) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jekyll-fridge/fridge_page.rb', line 20

def read_yaml_from_string(str)
  begin
    self.content = str
    if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
      self.content = $POSTMATCH
      self.data = SafeYAML.load($1)
    end
  rescue SyntaxError => e
    Jekyll.logger.warn "YAML Exception reading custom layout: #{e.message}"
  end

  self.data ||= {}
end