Class: Sitepress::Parsers::Frontmatter

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

Overview

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Frontmatter

Returns a new instance of Frontmatter.



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

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

Instance Method Details

#dataObject



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

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