Sha256: 64093f7171e2530d01ae939d7217a5c64a1981bf90a8dfba7eb37c0706614669
Contents?: true
Size: 1.04 KB
Versions: 89
Compression:
Stored size: 1.04 KB
Contents
module Brief class Document module FrontMatter extend ActiveSupport::Concern def frontmatter= attributes @frontmatter = attributes end def data= attributes self.frontmatter= attributes end def frontmatter (@frontmatter || load_frontmatter).tap do |d| d[:type] ||= parent_folder_name && parent_folder_name.to_s.singularize if parent_folder_name && parent_folder_name.length > 0 end end def frontmatter_line_count (@raw_frontmatter && @raw_frontmatter.lines.count) || 0 end protected def load_frontmatter if raw_content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m self.content = raw_content[(Regexp.last_match[1].size + Regexp.last_match[2].size)..-1] @frontmatter_line_count = Regexp.last_match[1].lines.size @raw_frontmatter = Regexp.last_match[1] @frontmatter = YAML.load(Regexp.last_match[1]).to_mash else @frontmatter = {}.to_mash end end end end end
Version data entries
89 entries across 89 versions & 1 rubygems