class Middleman::CoreExtensions::FrontMatter
Public Class Methods
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 24 def initialize(app, options_hash={}, &block) super @cache = {} end
Calls superclass method
Middleman::Extension::new
Public Instance Methods
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 30 def before_configuration app.files.on_change(:source, &method(:clear_data)) end
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 88 def clear_data(updated_files, removed_files) (updated_files + removed_files).each do |file| @cache.delete(file[:full_path].to_s) end end
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 72 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
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 36 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
Source
# File lib/middleman-core/core_extensions/front_matter.rb, line 67 def template_data_for_file(path) data(path).last end