Class: Mascot::Frontmatter

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

Overview

Parses metadata from the header of the page.

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.



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

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/mascot.rb', line 11

def body
  @body
end

Instance Method Details

#dataObject



17
18
19
# File 'lib/mascot.rb', line 17

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