Class: Sitepress::Frontmatter
- Inherits:
-
Object
- Object
- Sitepress::Frontmatter
- Defined in:
- lib/sitepress/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
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(content) ⇒ Frontmatter
constructor
A new instance of Frontmatter.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/sitepress/frontmatter.rb', line 13 def body @body end |
Instance Method Details
#data ⇒ Object
19 20 21 |
# File 'lib/sitepress/frontmatter.rb', line 19 def data @data ? YAML.load(@data) : {} end |