Module: Middleman::CoreExtensions::FrontMatter

Defined in:
lib/middleman-core/core_extensions/front_matter.rb

Overview

Frontmatter namespace

Defined Under Namespace

Modules: InstanceMethods, ResourceInstanceMethods Classes: FrontmatterManager

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object Also known as: included

Once registered



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 13

def registered(app)
  # Parsing YAML frontmatter
  require "yaml"

  # Parsing JSON frontmatter
  require "active_support/json"

  app.send :include, InstanceMethods

  app.before_configuration do
    files.changed { |file| frontmatter_manager.clear_data(file) }
    files.deleted { |file| frontmatter_manager.clear_data(file) }
  end

  app.after_configuration do
    ::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods

    sitemap.register_resource_list_manipulator(
      :frontmatter,
      frontmatter_manager
    )

    sitemap. do |path|
      fmdata = frontmatter_manager.data(path).first || {}

      data = {}
      %w(layout layout_engine).each do |opt|
        data[opt.to_sym] = fmdata[opt] unless fmdata[opt].nil?
      end

      { :options => data, :page => fmdata }
    end
  end
end