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
- PATTERN =
/\A(#{DELIMITER}\n(.+?)\n#{DELIMITER}\n*)?(.+)\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.
14 15 16 |
# File 'lib/sitepress/frontmatter.rb', line 14 def initialize(content) _, @data, @body = content.match(PATTERN).captures end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/sitepress/frontmatter.rb', line 12 def body @body end |
Instance Method Details
#data ⇒ Object
18 19 20 |
# File 'lib/sitepress/frontmatter.rb', line 18 def data @data ? YAML.load(@data) : {} end |