Get rid of raw_data

This commit is contained in:
Ben Hollis 2014-04-27 23:21:12 -07:00
parent 5c04c2f42b
commit adfad92f8f
7 changed files with 36 additions and 71 deletions

View file

@ -35,7 +35,9 @@ module Middleman::CoreExtensions
fmdata = data(resource.path).first
# Copy over special options
opts = fmdata.extract!(:layout, :layout_engine, :renderer_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)
if opts.has_key?(:renderer_options)
opts[:renderer_options].symbolize_keys!
end
@ -55,41 +57,6 @@ module Middleman::CoreExtensions
def after_configuration
app.ignore %r{\.frontmatter$}
# TODO: Replace all of this functionality
#::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
end
module ResourceInstanceMethods
def ignored?
if !proxy? && raw_data[:ignored] == true
true
else
super
end
end
# This page's frontmatter without being enhanced for access by either symbols or strings.
# Used internally
# @private
# @return [Hash]
def raw_data
app.extensions[:front_matter].data(source_file).first
end
# This page's frontmatter
# @return [Hash]
def data
@enhanced_data ||= ::Middleman::Util.recursively_enhance(raw_data).freeze
end
# Override Resource#content_type to take into account frontmatter
def content_type
# Allow setting content type in frontmatter too
raw_data.fetch :content_type do
super
end
end
end
# Get the template data from a path

View file

@ -16,11 +16,8 @@ class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
resource.destination_path.end_with?(new_index_path) ||
File.extname(index_file) != resource.ext
# Check if frontmatter turns directory_index off
next if resource.raw_data[:directory_index] == false
# Check if file metadata (options set by "page" in config.rb) turns directory_index off
next if resource.metadata[:options][:directory_index] == false
# Check if file metadata (options set by "page" in config.rb or frontmatter) turns directory_index off
next if resource.options[:directory_index] == false
resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
end

View file

@ -5,8 +5,8 @@ module Middleman::Sitemap::Extensions
module ContentType
# The preferred MIME content type for this resource
def content_type
# Allow explcitly setting content type from page/proxy options
meta_type = metadata[:options][:content_type]
# Allow explcitly setting content type from page/proxy options or frontmatter
meta_type = options[:content_type]
return meta_type if meta_type
# Look up mime type based on extension

View file

@ -51,10 +51,12 @@ module Middleman
# Whether the Resource is ignored
# @return [Boolean]
def ignored?
@app.sitemap.ignored?(path) ||
(!proxy? &&
@app.sitemap.ignored?(source_file.sub("#{@app.source_dir}/", ''))
)
# Check frontmatter/data
return true if !proxy? && data[:ignored] == true
# Ignore based on the source path (without template extensions)
return true if @app.sitemap.ignored?(path)
# This allows files to be ignored by their source file name (with template extensions)
!proxy? && @app.sitemap.ignored?(source_file.sub("#{@app.source_dir}/", ''))
end
end
end

View file

@ -75,18 +75,10 @@ module Middleman
end
end
# def request_path
# @request_path
# end
def binary?
false
end
def raw_data
{}
end
def ignored?
false
end

View file

@ -63,16 +63,10 @@ module Middleman
return output.call if output
end
attr_reader :request_path
def binary?
false
end
def raw_data
{}
end
def ignored?
false
end

View file

@ -52,6 +52,16 @@ module Middleman
!::Tilt[source_file].nil?
end
# Merge in new metadata specific to this resource.
# @param [Hash] meta A metadata block with keys :options, :locals, :page.
# Options are generally rendering/sitemap options
# Locals are local variables for rendering this resource's template
# Page are data that is exposed through this resource's data member.
# Note: It is named 'page' for backwards compatibility with older MM.
def add_metadata(meta={})
@local_metadata.deep_merge!(meta)
end
# Get the metadata for both the current source_file and the current path
# @return [Hash]
def metadata
@ -62,18 +72,21 @@ module Middleman
# Data about this resource, populated from frontmatter or extensions.
# @return [HashWithIndifferentAccess]
def data
# TODO: Upconvert/freeze at this point?
metadata[:page]
# TODO: Should this really be a HashWithIndifferentAccess?
::Middleman::Util.recursively_enhance(metadata[:page]).freeze
end
# Merge in new metadata specific to this resource.
# @param [Hash] meta A metadata block with keys :options, :locals, :page.
# Options are generally rendering/sitemap options
# Locals are local variables for rendering this resource's template
# Page are data that is exposed through this resource's data member.
# Note: It is named 'page' for backwards compatibility with older MM.
def add_metadata(meta={})
@local_metadata.deep_merge!(meta)
# Options about how this resource is rendered, such as its :layout,
# :renderer_options, and whether or not to use :directory_indexes.
# @return [Hash]
def options
metadata[:options]
end
# Local variable mappings that are used when rendering the template for this resource.
# @return [Hash]
def locals
metadata[:locals]
end
# Extension of the path (i.e. '.js')