class Middleman::CoreExtensions::FrontMatter

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method Middleman::Extension::new
# File lib/middleman-core/core_extensions/front_matter.rb, line 23
def initialize(app, options_hash={}, &block)
  super

  @cache = {}
end

Public Instance Methods

before_configuration() click to toggle source
# File lib/middleman-core/core_extensions/front_matter.rb, line 29
def before_configuration
  app.files.on_change(:source, &method(:clear_data))
end
clear_data(updated_files, removed_files) click to toggle source
# File lib/middleman-core/core_extensions/front_matter.rb, line 87
def clear_data(updated_files, removed_files)
  (updated_files + removed_files).each do |file|
    @cache.delete(file[:full_path].to_s)
  end
end
data(path) click to toggle source
# File lib/middleman-core/core_extensions/front_matter.rb, line 71
def data(path)
  file = app.files.find(:source, path)

  return [{}, nil] unless file

  file_path = file[:full_path].to_s

  @cache[file_path] ||= begin
    ::Middleman::Util::Data.parse(
      file,
      app.config[:frontmatter_delims]
    )
  end
end
manipulate_resource_list(resources) click to toggle source
# File lib/middleman-core/core_extensions/front_matter.rb, line 35
def manipulate_resource_list(resources)
  resources.each do |resource|
    next if resource.binary?
    next if resource.file_descriptor.nil?
    next if resource.file_descriptor[:types].include?(:no_frontmatter)

    fmdata = data(resource.file_descriptor[:full_path].to_s).first.dup

    # Copy over special options
    # TODO: Should we make people put these under "options" instead of having
    # special known keys?
    opts = fmdata.extract!(:layout, :layout_engine, :renderer_options, :directory_index, :content_type)
    opts[:renderer_options].symbolize_keys! if opts.key?(:renderer_options)

    ignored = fmdata.delete(:ignored)

    # TODO: Enhance data? NOOOO
    # TODO: stringify-keys? immutable/freeze?

    resource.add_metadata options: opts, page: fmdata

    resource.ignore! if ignored == true && !resource.is_a?(::Middleman::Sitemap::ProxyResource)

    # TODO: Save new template here somewhere?
  end
end
template_data_for_file(path) click to toggle source
# File lib/middleman-core/core_extensions/front_matter.rb, line 66
def template_data_for_file(path)
  data(path).last
end