lib/yarrow/tools/content_utils.rb
# Pass in a source path and get back a parsed representation of the
# content if it is in a known text format. Mostly used as a fallback if
# a custom parser or processing chain is not configured for a content
# type.
#
# Supported formats:
# - HTML template and document partials
# - Markdown documents
# - YAML documents
# - JSON (untested)
#
# Works around meta and content source in multiple files or a single
# file with front matter.
Pass in a source path and get back a parsed representation of the
content if it is in a known text format. Mostly used as a fallback if
a custom parser or processing chain is not configured for a content
type.

Supported formats:
HTML template and document partials
Markdown documents
YAML documents
JSON (untested)

Works around meta and content source in multiple files or a single
file with front matter.
Pass in a source path and get back a parsed representation of the content if it is in a known text format . Mostly used as a fallback if a custom parser or processing chain is not configured for a content type . Supported formats : HTML template and document partials Markdown documents YAML documents JSON ( untested ) Works around meta and content source in multiple files or a single file with front matter .
def extract_yfm(text, options={})
        pattern = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
        if text =~ pattern
          content = text.sub(pattern, "")
          begin
            if options.key?(:symbolize_keys)
              meta = YAML.load($1, symbolize_names: true)
            else
              meta = YAML.load($1)
            end
            return [content, meta]
          rescue Psych::SyntaxError => error
            if defined? ::Logger
            end
            return [content, nil]
          end
        end
        [text, nil]
      end
def extract_yfm ( text , options = { } ) pattern = / ^(--- \s * \n .*? \n ?)^(--- \s *$ \n ?) /m if text =~ pattern content = text . sub ( pattern , "" ) begin if options . key? ( :symbolize_keys ) meta = YAML . load ( $1 , symbolize_names : true ) else meta = YAML . load ( $1 ) end return [ content , meta ] rescue Psych :: SyntaxError => error if defined? :: Logger end return [ content , nil ] end end [ text , nil ] end
Pass in a source path and get back a parsed representation of the
content if it is in a known text format.
Pass in a source path and get back a parsed representation of the content if it is in a known text format .
# todo: application wide logger #logger = ::Logger.new(STDOUT) #logger.error "#{error.message}"
text
<not_specific>
options
<not_specific>