Run helper after collections. Fixes #1226
This commit is contained in:
parent
4733488e8d
commit
0d983231d0
|
@ -11,6 +11,22 @@ Feature: Custom layouts
|
|||
When I go to "/custom-layout.html"
|
||||
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
|
||||
Given a fixture app "custom-layout-app2"
|
||||
And a file named "config.rb" with:
|
||||
|
|
|
@ -97,7 +97,7 @@ module Middleman
|
|||
|
||||
::Middleman::Util.instrument 'builder.prerender.check-files' do
|
||||
# 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'
|
||||
@app.sitemap.ensure_resource_list_updated!
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ module Middleman
|
|||
|
||||
# Allow configuration settings to be read and written via methods
|
||||
def method_missing(method, *args)
|
||||
if defines_setting?(method) && args.size == 0
|
||||
if defines_setting?(method) && args.empty?
|
||||
self[method]
|
||||
elsif method.to_s =~ /^(\w+)=$/ && args.size == 1
|
||||
self[$1.to_sym] = args[0]
|
||||
|
|
|
@ -102,7 +102,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
locale_suffix = ::I18n.locale
|
||||
|
||||
extname = File.extname(partial_name)
|
||||
maybe_static = extname.length > 0
|
||||
maybe_static = !extname.empty?
|
||||
suffixed_partial_name = if maybe_static
|
||||
partial_name.sub(extname, ".#{locale_suffix}#{extname}")
|
||||
else
|
||||
|
|
|
@ -4,7 +4,7 @@ module Middleman
|
|||
class Routing < ConfigExtension
|
||||
# This should always run late, but not as late as :directory_indexes,
|
||||
# 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_to_config :page
|
||||
|
@ -25,7 +25,7 @@ module Middleman
|
|||
|
||||
resources
|
||||
.select { |r| ::Middleman::Util.path_match(normalized_path, "/#{r.path}") }
|
||||
.each { |r| r.add_metadata(metadata) }
|
||||
.each { |r| r.add_metadata(metadata, true) }
|
||||
|
||||
resources
|
||||
end
|
||||
|
|
|
@ -402,11 +402,11 @@ module Middleman
|
|||
ext.after_configuration if ext.respond_to?(:after_configuration)
|
||||
|
||||
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
|
||||
|
||||
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,
|
||||
ext.class.resource_list_manipulator_priority,
|
||||
|
|
|
@ -30,7 +30,7 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|||
::IO.popen(options[:command], 'r') do |pipe|
|
||||
while buf = pipe.gets
|
||||
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
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module Middleman
|
|||
# The Middleman Logger
|
||||
class Logger < ActiveSupport::Logger
|
||||
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))
|
||||
args = [0, false, args.first]
|
||||
end
|
||||
|
|
|
@ -125,7 +125,7 @@ module Middleman
|
|||
|
||||
# Halt request and return 404
|
||||
def not_found(res, path)
|
||||
path = ::Rack::Utils::escape_html(path)
|
||||
path = ::Rack::Utils.escape_html(path)
|
||||
res.status = 404
|
||||
res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>"
|
||||
res.finish
|
||||
|
|
|
@ -76,7 +76,7 @@ module Middleman
|
|||
scope.image_tag(link, title: title, alt: alt_text)
|
||||
else
|
||||
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})"
|
||||
end
|
||||
end
|
||||
|
@ -89,7 +89,7 @@ module Middleman
|
|||
scope.link_to(content, link, attributes)
|
||||
else
|
||||
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})"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,10 +96,15 @@ module Middleman
|
|||
# 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.
|
||||
Contract METADATA_HASH => METADATA_HASH
|
||||
def add_metadata(meta={})
|
||||
Contract METADATA_HASH, Maybe[Bool] => METADATA_HASH
|
||||
def add_metadata(meta={}, reverse=false)
|
||||
@page_data = nil
|
||||
@metadata.deep_merge!(meta)
|
||||
|
||||
@metadata = if reverse
|
||||
meta.deep_merge(@metadata)
|
||||
else
|
||||
@metadata.deep_merge(meta)
|
||||
end
|
||||
end
|
||||
|
||||
# Data about this resource, populated from frontmatter or extensions.
|
||||
|
|
|
@ -87,6 +87,13 @@ module Middleman
|
|||
@app.config_context.class.send :def_delegator, :app, :sitemap
|
||||
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
|
||||
# these in a `before_configuration` or `after_configuration` hook.
|
||||
#
|
||||
|
@ -221,7 +228,7 @@ module Middleman
|
|||
|
||||
@resource_list_manipulators.each do |m|
|
||||
::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)
|
||||
|
||||
# Reset lookup cache
|
||||
|
|
|
@ -104,30 +104,19 @@ module Middleman
|
|||
sass_type_aliasing = ['.scss', '.sass']
|
||||
erb_type_aliasing = ['.erb', '.haml', '.slim']
|
||||
|
||||
if (all_extensions & sass_type_aliasing).length > 0
|
||||
all_extensions |= sass_type_aliasing
|
||||
end
|
||||
|
||||
if (all_extensions & erb_type_aliasing).length > 0
|
||||
all_extensions |= erb_type_aliasing
|
||||
end
|
||||
all_extensions |= sass_type_aliasing unless (all_extensions & sass_type_aliasing).empty?
|
||||
all_extensions |= erb_type_aliasing unless (all_extensions & erb_type_aliasing).empty?
|
||||
|
||||
all_extensions.uniq!
|
||||
|
||||
app.sitemap.resources.select(&:file_descriptor).select { |r|
|
||||
local_extensions = collect_extensions(r.file_descriptor[:full_path].to_s)
|
||||
|
||||
if (local_extensions & sass_type_aliasing).length > 0
|
||||
local_extensions |= sass_type_aliasing
|
||||
end
|
||||
|
||||
if (local_extensions & erb_type_aliasing).length > 0
|
||||
local_extensions |= erb_type_aliasing
|
||||
end
|
||||
local_extensions |= sass_type_aliasing unless (local_extensions & sass_type_aliasing).empty?
|
||||
local_extensions |= erb_type_aliasing unless (local_extensions & erb_type_aliasing).empty?
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue