Class: Sitepress::Parsers::Frontmatter

Inherits:
Base
  • Object
show all
Defined in:
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

Attributes inherited from Base

#body

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Frontmatter

Returns a new instance of Frontmatter.



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

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

Instance Method Details

#dataObject



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

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