Class: Sitepress::Frontmatter

Inherits:
Object
  • Object
show all
Defined in:
lib/sitepress/frontmatter.rb

Overview

TODO: Redo this to use File readline and pos to perform faster

Constant Summary collapse

DELIMITER =
"---".freeze
PATTERN =
/\A(#{DELIMITER}\n(.+?)\n#{DELIMITER}\n*)?(.+)\Z/m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Frontmatter

Returns a new instance of Frontmatter.



14
15
16
# File 'lib/sitepress/frontmatter.rb', line 14

def initialize(content)
  _, @data, @body = content.match(PATTERN).captures
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/sitepress/frontmatter.rb', line 12

def body
  @body
end

Instance Method Details

#dataObject



18
19
20
# File 'lib/sitepress/frontmatter.rb', line 18

def data
  @data ? YAML.load(@data) : {}
end