module Pakyow::Presenter::FrontMatterParser
Parses front matter from text files.
@api private
Constants
- MATTER_MATCHER
Public Class Methods
parse(html_string, _file = nil)
click to toggle source
Parses HTML and returns a hash of front matter info
# 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)
click to toggle source
Parses HTML and returns:
-
a hash of front matter info
-
the HTML with front matter removed
# 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)
click to toggle source
Returns HTML with front matter removed
# File lib/pakyow/presenter/front_matter_parser.rb, line 29 def self.scrub(html_string) html_string.gsub(MATTER_MATCHER, "") end