Module: Pakyow::Presenter::FrontMatterParser Private

Defined in:
lib/pakyow/presenter/front_matter_parser.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parses front matter from text files.

API:

  • private

Constant Summary collapse

MATTER_MATCHER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

/\A---\s*\n(.*?\n?)^---\s*$\n?/m

Class Method Summary collapse

Class Method Details

.parse(html_string, _file = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses HTML and returns a hash of front matter info

API:

  • private



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pakyow/presenter/front_matter_parser.rb', line 15

def self.parse(html_string, _file = nil)
  unless match = html_string.match(MATTER_MATCHER)
    return Support::IndifferentHash.new
  end

  begin
    Support::IndifferentHash.deep(YAML.load(match.captures[0]).to_h)
  rescue Psych::SyntaxError => error
    raise FrontMatterParsingError.build(error, context: match.captures[0])
  end
end

.parse_and_scrub(html_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses HTML and returns:

  • a hash of front matter info
  • the HTML with front matter removed

API:

  • private



37
38
39
# File 'lib/pakyow/presenter/front_matter_parser.rb', line 37

def self.parse_and_scrub(html_string)
  return parse(html_string), scrub(html_string)
end

.scrub(html_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns HTML with front matter removed

API:

  • private



29
30
31
# File 'lib/pakyow/presenter/front_matter_parser.rb', line 29

def self.scrub(html_string)
  html_string.gsub(MATTER_MATCHER, "")
end