Sha256: 8073ce8050ed09558d192e6ebbc89c1e9e5c4fb1dc926b45ecec19e33b5533d2
Contents?: true
Size: 1.27 KB
Versions: 13
Compression:
Stored size: 1.27 KB
Contents
module Munge class System class ItemFactory class ContentParser def self.match(string) string.match(/ # Start of string \A # Begin frontmatter (?:^---\s*[\n\r]+) # Capture frontmatter (.*) # End frontmatter (?:^---\s*[\n\r]+) /mx) end def self.parse(string) matchdata = match(string) [ parse_frontmatter(matchdata), parse_content(matchdata, string) ] end def self.parse_frontmatter(matchdata) return {} if matchdata.nil? parsed_frontmatter = YAML.load(matchdata[1]) frontmatter_hash = if parsed_frontmatter.is_a?(Hash) parsed_frontmatter else {} end Munge::Util::SymbolHash.deep_convert(frontmatter_hash) end def self.parse_content(matchdata, string) if matchdata matchdata.post_match else string end end def initialize(string) @frontmatter, @content = self.class.parse(string) end attr_accessor :frontmatter, :content end end end end
Version data entries
13 entries across 13 versions & 1 rubygems