module Yarrow::Tools::FrontMatter

@deprecated Maintained here as it is still used in a number of places but needs to be removed soon

Public Instance Methods

extract_split_content(text, options={}) click to toggle source
# File lib/yarrow/tools/front_matter.rb, line 11
def extract_split_content(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
        # todo: application wide logger
        #logger = ::Logger.new(STDOUT)
        #logger.error "#{error.message}"
      end
      return [content, nil]
    end
  end

  [text, nil]
end
read_split_content(path, options={}) click to toggle source
# File lib/yarrow/tools/front_matter.rb, line 7
def read_split_content(path, options={})
  extract_split_content(File.read(path, :encoding => 'utf-8'), options)
end