Run helper after collections. Fixes #1226

This commit is contained in:
Thomas Reynolds 2016-02-24 14:20:42 -08:00
parent 4733488e8d
commit 0d983231d0
13 changed files with 50 additions and 33 deletions

View file

@ -11,6 +11,22 @@ Feature: Custom layouts
When I go to "/custom-layout.html" When I go to "/custom-layout.html"
Then I should see "Custom Layout" Then I should see "Custom Layout"
Scenario: Using custom :layout attribute with proxy
Given a fixture app "custom-layout-app2"
And a file named "config.rb" with:
"""
page '/test/*', layout: :custom
proxy "/test/me.html", "/custom-layout.html"
live { %w(you) }.each do |who|
proxy "/test/#{who}.html", "/custom-layout.html"
end
"""
And the Server is running at "custom-layout-app2"
When I go to "/test/me.html"
Then I should see "Custom Layout"
When I go to "/test/you.html"
Then I should see "Custom Layout"
Scenario: Using custom :layout attribute with folders Scenario: Using custom :layout attribute with folders
Given a fixture app "custom-layout-app2" Given a fixture app "custom-layout-app2"
And a file named "config.rb" with: And a file named "config.rb" with:
@ -65,4 +81,4 @@ Feature: Custom layouts
When I go to "/path/index.html" When I go to "/path/index.html"
Then I should see "Alt" Then I should see "Alt"
And I should see "Monde" And I should see "Monde"
And I should not see "Hello" And I should not see "Hello"

View file

@ -97,7 +97,7 @@ module Middleman
::Middleman::Util.instrument 'builder.prerender.check-files' do ::Middleman::Util.instrument 'builder.prerender.check-files' do
# Double-check for compass sprites # Double-check for compass sprites
if @app.files.find_new_files!.length > 0 unless @app.files.find_new_files!.empty?
logger.debug '== Checking for Compass sprites' logger.debug '== Checking for Compass sprites'
@app.sitemap.ensure_resource_list_updated! @app.sitemap.ensure_resource_list_updated!
end end

View file

@ -40,7 +40,7 @@ module Middleman
# Allow configuration settings to be read and written via methods # Allow configuration settings to be read and written via methods
def method_missing(method, *args) def method_missing(method, *args)
if defines_setting?(method) && args.size == 0 if defines_setting?(method) && args.empty?
self[method] self[method]
elsif method.to_s =~ /^(\w+)=$/ && args.size == 1 elsif method.to_s =~ /^(\w+)=$/ && args.size == 1
self[$1.to_sym] = args[0] self[$1.to_sym] = args[0]

View file

@ -102,7 +102,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
locale_suffix = ::I18n.locale locale_suffix = ::I18n.locale
extname = File.extname(partial_name) extname = File.extname(partial_name)
maybe_static = extname.length > 0 maybe_static = !extname.empty?
suffixed_partial_name = if maybe_static suffixed_partial_name = if maybe_static
partial_name.sub(extname, ".#{locale_suffix}#{extname}") partial_name.sub(extname, ".#{locale_suffix}#{extname}")
else else

View file

@ -4,7 +4,7 @@ module Middleman
class Routing < ConfigExtension class Routing < ConfigExtension
# This should always run late, but not as late as :directory_indexes, # This should always run late, but not as late as :directory_indexes,
# so it can add metadata to any pages generated by other extensions # so it can add metadata to any pages generated by other extensions
self.resource_list_manipulator_priority = 10 self.resource_list_manipulator_priority = [10, 130]
# Expose the `page` method to config. # Expose the `page` method to config.
expose_to_config :page expose_to_config :page
@ -25,7 +25,7 @@ module Middleman
resources resources
.select { |r| ::Middleman::Util.path_match(normalized_path, "/#{r.path}") } .select { |r| ::Middleman::Util.path_match(normalized_path, "/#{r.path}") }
.each { |r| r.add_metadata(metadata) } .each { |r| r.add_metadata(metadata, true) }
resources resources
end end

View file

@ -402,11 +402,11 @@ module Middleman
ext.after_configuration if ext.respond_to?(:after_configuration) ext.after_configuration if ext.respond_to?(:after_configuration)
if ext.respond_to?(:manipulate_resource_list) if ext.respond_to?(:manipulate_resource_list)
ext.app.sitemap.register_resource_list_manipulator(ext.class.ext_name, ext, ext.class.resource_list_manipulator_priority) ext.app.sitemap.register_resource_list_manipulators(ext.class.ext_name, ext, ext.class.resource_list_manipulator_priority)
end end
if ext.class.resources_generators && !ext.class.resources_generators.empty? if ext.class.resources_generators && !ext.class.resources_generators.empty?
ext.app.sitemap.register_resource_list_manipulator( ext.app.sitemap.register_resource_list_manipulators(
:"#{ext.class.ext_name}_generator", :"#{ext.class.ext_name}_generator",
ext, ext,
ext.class.resource_list_manipulator_priority, ext.class.resource_list_manipulator_priority,

View file

@ -30,7 +30,7 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
::IO.popen(options[:command], 'r') do |pipe| ::IO.popen(options[:command], 'r') do |pipe|
while buf = pipe.gets while buf = pipe.gets
without_newline = buf.sub(/\n$/, '') without_newline = buf.sub(/\n$/, '')
logger.info "== External: #{without_newline}" if without_newline.length > 0 logger.info "== External: #{without_newline}" unless without_newline.empty?
end end
end end

View file

@ -7,7 +7,7 @@ module Middleman
# The Middleman Logger # The Middleman Logger
class Logger < ActiveSupport::Logger class Logger < ActiveSupport::Logger
def self.singleton(*args) def self.singleton(*args)
if !@_logger || args.length > 0 if !@_logger || !args.empty?
if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write)) if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
args = [0, false, args.first] args = [0, false, args.first]
end end

View file

@ -125,7 +125,7 @@ module Middleman
# Halt request and return 404 # Halt request and return 404
def not_found(res, path) def not_found(res, path)
path = ::Rack::Utils::escape_html(path) path = ::Rack::Utils.escape_html(path)
res.status = 404 res.status = 404
res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>" res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>"
res.finish res.finish

View file

@ -76,7 +76,7 @@ module Middleman
scope.image_tag(link, title: title, alt: alt_text) scope.image_tag(link, title: title, alt: alt_text)
else else
link_string = link.dup link_string = link.dup
link_string << %("#{title}") if title && title.length > 0 && title != alt_text link_string << %("#{title}") if title && !title.empty? && title != alt_text
"![#{alt_text}](#{link_string})" "![#{alt_text}](#{link_string})"
end end
end end
@ -89,7 +89,7 @@ module Middleman
scope.link_to(content, link, attributes) scope.link_to(content, link, attributes)
else else
link_string = link.dup link_string = link.dup
link_string << %("#{title}") if title && title.length > 0 && title != alt_text link_string << %("#{title}") if title && !title.empty? && title != alt_text
"[#{content}](#{link_string})" "[#{content}](#{link_string})"
end end
end end

View file

@ -96,10 +96,15 @@ module Middleman
# Locals are local variables for rendering this resource's template # Locals are local variables for rendering this resource's template
# Page are data that is exposed through this resource's data member. # Page are data that is exposed through this resource's data member.
# Note: It is named 'page' for backwards compatibility with older MM. # Note: It is named 'page' for backwards compatibility with older MM.
Contract METADATA_HASH => METADATA_HASH Contract METADATA_HASH, Maybe[Bool] => METADATA_HASH
def add_metadata(meta={}) def add_metadata(meta={}, reverse=false)
@page_data = nil @page_data = nil
@metadata.deep_merge!(meta)
@metadata = if reverse
meta.deep_merge(@metadata)
else
@metadata.deep_merge(meta)
end
end end
# Data about this resource, populated from frontmatter or extensions. # Data about this resource, populated from frontmatter or extensions.

View file

@ -87,6 +87,13 @@ module Middleman
@app.config_context.class.send :def_delegator, :app, :sitemap @app.config_context.class.send :def_delegator, :app, :sitemap
end end
Contract Symbol, RespondTo[:manipulate_resource_list], Maybe[Or[Num, ArrayOf[Num]]], Maybe[Symbol] => Any
def register_resource_list_manipulators(name, manipulator, priority=50, custom_name=nil)
Array(priority || 50).each do |p|
register_resource_list_manipulator(name, manipulator, p, custom_name)
end
end
# Register an object which can transform the sitemap resource list. Best to register # Register an object which can transform the sitemap resource list. Best to register
# these in a `before_configuration` or `after_configuration` hook. # these in a `before_configuration` or `after_configuration` hook.
# #
@ -221,7 +228,7 @@ module Middleman
@resource_list_manipulators.each do |m| @resource_list_manipulators.each do |m|
::Middleman::Util.instrument 'sitemap.manipulator', name: m[:name] do ::Middleman::Util.instrument 'sitemap.manipulator', name: m[:name] do
@app.logger.debug "== Running manipulator: #{m[:name]}" @app.logger.debug "== Running manipulator: #{m[:name]} (#{m[:priority]})"
@resources = m[:manipulator].send(m[:custom_name] || :manipulate_resource_list, @resources) @resources = m[:manipulator].send(m[:custom_name] || :manipulate_resource_list, @resources)
# Reset lookup cache # Reset lookup cache

View file

@ -104,30 +104,19 @@ module Middleman
sass_type_aliasing = ['.scss', '.sass'] sass_type_aliasing = ['.scss', '.sass']
erb_type_aliasing = ['.erb', '.haml', '.slim'] erb_type_aliasing = ['.erb', '.haml', '.slim']
if (all_extensions & sass_type_aliasing).length > 0 all_extensions |= sass_type_aliasing unless (all_extensions & sass_type_aliasing).empty?
all_extensions |= sass_type_aliasing all_extensions |= erb_type_aliasing unless (all_extensions & erb_type_aliasing).empty?
end
if (all_extensions & erb_type_aliasing).length > 0
all_extensions |= erb_type_aliasing
end
all_extensions.uniq! all_extensions.uniq!
app.sitemap.resources.select(&:file_descriptor).select { |r| app.sitemap.resources.select(&:file_descriptor).select { |r|
local_extensions = collect_extensions(r.file_descriptor[:full_path].to_s) local_extensions = collect_extensions(r.file_descriptor[:full_path].to_s)
local_extensions |= sass_type_aliasing unless (local_extensions & sass_type_aliasing).empty?
if (local_extensions & sass_type_aliasing).length > 0 local_extensions |= erb_type_aliasing unless (local_extensions & erb_type_aliasing).empty?
local_extensions |= sass_type_aliasing
end
if (local_extensions & erb_type_aliasing).length > 0
local_extensions |= erb_type_aliasing
end
local_extensions.uniq! local_extensions.uniq!
((all_extensions & local_extensions).length > 0) && files.none? { |f| f == r.file_descriptor[:full_path] } !(all_extensions & local_extensions).empty? && files.none? { |f| f == r.file_descriptor[:full_path] }
}.map(&:file_descriptor) }.map(&:file_descriptor)
end end
end end