Class: Gollum::Filter::YAML

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/yaml.rb

Overview

Extract YAML frontmatter from data and build metadata table.

Constant Summary collapse

YAML_FRONT_MATTER_REGEXP =

Regexp thanks to jekyll

%r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m

Constants inherited from Gollum::Filter

PLACEHOLDER_PATTERN

Instance Attribute Summary

Attributes inherited from Gollum::Filter

#close_pattern, #open_pattern

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#path_to_link_text, #trim_leading_slashes

Constructor Details

This class inherits a constructor from Gollum::Filter

Instance Method Details

#extract(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gollum-lib/filter/yaml.rb', line 9

def extract(data)
  data.gsub!(YAML_FRONT_MATTER_REGEXP) do
    @markup. ||= {}
    begin
      frontmatter = ::YAML.safe_load(sanitize(Regexp.last_match[1]))
      @markup..merge!(frontmatter) if frontmatter.respond_to?(:keys) && frontmatter.respond_to?(:values)
    rescue ::Psych::SyntaxError, ::Psych::DisallowedClass, ::Psych::BadAlias => error
      @markup.['errors'] ||= []
      @markup.['errors'] << "Failed to load YAML frontmatter: #{error.message}"
    end
    ''
  end
  data
end

#process(data) ⇒ Object



24
25
26
# File 'lib/gollum-lib/filter/yaml.rb', line 24

def process(data)
  data
end