Get rid of raw_data
This commit is contained in:
parent
5c04c2f42b
commit
adfad92f8f
7 changed files with 36 additions and 71 deletions
|
@ -35,7 +35,9 @@ module Middleman::CoreExtensions
|
||||||
fmdata = data(resource.path).first
|
fmdata = data(resource.path).first
|
||||||
|
|
||||||
# Copy over special options
|
# 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)
|
if opts.has_key?(:renderer_options)
|
||||||
opts[:renderer_options].symbolize_keys!
|
opts[:renderer_options].symbolize_keys!
|
||||||
end
|
end
|
||||||
|
@ -55,41 +57,6 @@ module Middleman::CoreExtensions
|
||||||
|
|
||||||
def after_configuration
|
def after_configuration
|
||||||
app.ignore %r{\.frontmatter$}
|
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
|
end
|
||||||
|
|
||||||
# Get the template data from a path
|
# Get the template data from a path
|
||||||
|
|
|
@ -16,11 +16,8 @@ class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
|
||||||
resource.destination_path.end_with?(new_index_path) ||
|
resource.destination_path.end_with?(new_index_path) ||
|
||||||
File.extname(index_file) != resource.ext
|
File.extname(index_file) != resource.ext
|
||||||
|
|
||||||
# Check if frontmatter turns directory_index off
|
# Check if file metadata (options set by "page" in config.rb or frontmatter) turns directory_index off
|
||||||
next if resource.raw_data[:directory_index] == false
|
next if resource.options[: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
|
|
||||||
|
|
||||||
resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
|
resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,8 @@ module Middleman::Sitemap::Extensions
|
||||||
module ContentType
|
module ContentType
|
||||||
# The preferred MIME content type for this resource
|
# The preferred MIME content type for this resource
|
||||||
def content_type
|
def content_type
|
||||||
# Allow explcitly setting content type from page/proxy options
|
# Allow explcitly setting content type from page/proxy options or frontmatter
|
||||||
meta_type = metadata[:options][:content_type]
|
meta_type = options[:content_type]
|
||||||
return meta_type if meta_type
|
return meta_type if meta_type
|
||||||
|
|
||||||
# Look up mime type based on extension
|
# Look up mime type based on extension
|
||||||
|
|
|
@ -51,10 +51,12 @@ module Middleman
|
||||||
# Whether the Resource is ignored
|
# Whether the Resource is ignored
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def ignored?
|
def ignored?
|
||||||
@app.sitemap.ignored?(path) ||
|
# Check frontmatter/data
|
||||||
(!proxy? &&
|
return true if !proxy? && data[:ignored] == true
|
||||||
@app.sitemap.ignored?(source_file.sub("#{@app.source_dir}/", ''))
|
# 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,18 +75,10 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# def request_path
|
|
||||||
# @request_path
|
|
||||||
# end
|
|
||||||
|
|
||||||
def binary?
|
def binary?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_data
|
|
||||||
{}
|
|
||||||
end
|
|
||||||
|
|
||||||
def ignored?
|
def ignored?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,16 +63,10 @@ module Middleman
|
||||||
return output.call if output
|
return output.call if output
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :request_path
|
|
||||||
|
|
||||||
def binary?
|
def binary?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_data
|
|
||||||
{}
|
|
||||||
end
|
|
||||||
|
|
||||||
def ignored?
|
def ignored?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,16 @@ module Middleman
|
||||||
!::Tilt[source_file].nil?
|
!::Tilt[source_file].nil?
|
||||||
end
|
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
|
# Get the metadata for both the current source_file and the current path
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def metadata
|
def metadata
|
||||||
|
@ -62,18 +72,21 @@ module Middleman
|
||||||
# Data about this resource, populated from frontmatter or extensions.
|
# Data about this resource, populated from frontmatter or extensions.
|
||||||
# @return [HashWithIndifferentAccess]
|
# @return [HashWithIndifferentAccess]
|
||||||
def data
|
def data
|
||||||
# TODO: Upconvert/freeze at this point?
|
# TODO: Should this really be a HashWithIndifferentAccess?
|
||||||
metadata[:page]
|
::Middleman::Util.recursively_enhance(metadata[:page]).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge in new metadata specific to this resource.
|
# Options about how this resource is rendered, such as its :layout,
|
||||||
# @param [Hash] meta A metadata block with keys :options, :locals, :page.
|
# :renderer_options, and whether or not to use :directory_indexes.
|
||||||
# Options are generally rendering/sitemap options
|
# @return [Hash]
|
||||||
# Locals are local variables for rendering this resource's template
|
def options
|
||||||
# Page are data that is exposed through this resource's data member.
|
metadata[:options]
|
||||||
# Note: It is named 'page' for backwards compatibility with older MM.
|
end
|
||||||
def add_metadata(meta={})
|
|
||||||
@local_metadata.deep_merge!(meta)
|
# Local variable mappings that are used when rendering the template for this resource.
|
||||||
|
# @return [Hash]
|
||||||
|
def locals
|
||||||
|
metadata[:locals]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extension of the path (i.e. '.js')
|
# Extension of the path (i.e. '.js')
|
||||||
|
|
Loading…
Add table
Reference in a new issue