diff --git a/middleman-core/features/custom_layouts.feature b/middleman-core/features/custom_layouts.feature index 27f7df08..dfe52344 100644 --- a/middleman-core/features/custom_layouts.feature +++ b/middleman-core/features/custom_layouts.feature @@ -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: @@ -65,4 +81,4 @@ Feature: Custom layouts When I go to "/path/index.html" Then I should see "Alt" And I should see "Monde" - And I should not see "Hello" \ No newline at end of file + And I should not see "Hello" diff --git a/middleman-core/lib/middleman-core/builder.rb b/middleman-core/lib/middleman-core/builder.rb index 9bb3c031..d2235c5f 100644 --- a/middleman-core/lib/middleman-core/builder.rb +++ b/middleman-core/lib/middleman-core/builder.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/configuration.rb b/middleman-core/lib/middleman-core/configuration.rb index 3f889c00..c916fc90 100644 --- a/middleman-core/lib/middleman-core/configuration.rb +++ b/middleman-core/lib/middleman-core/configuration.rb @@ -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] diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 9f7503b8..ac86d9a0 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/routing.rb b/middleman-core/lib/middleman-core/core_extensions/routing.rb index b10fba53..f47ac16b 100644 --- a/middleman-core/lib/middleman-core/core_extensions/routing.rb +++ b/middleman-core/lib/middleman-core/core_extensions/routing.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/extension.rb b/middleman-core/lib/middleman-core/extension.rb index e8e36af0..d9dc01ca 100644 --- a/middleman-core/lib/middleman-core/extension.rb +++ b/middleman-core/lib/middleman-core/extension.rb @@ -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, diff --git a/middleman-core/lib/middleman-core/extensions/external_pipeline.rb b/middleman-core/lib/middleman-core/extensions/external_pipeline.rb index 0e09dc17..d4a5aab5 100644 --- a/middleman-core/lib/middleman-core/extensions/external_pipeline.rb +++ b/middleman-core/lib/middleman-core/extensions/external_pipeline.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/logger.rb b/middleman-core/lib/middleman-core/logger.rb index 30e28307..1c0170d1 100644 --- a/middleman-core/lib/middleman-core/logger.rb +++ b/middleman-core/lib/middleman-core/logger.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/rack.rb b/middleman-core/lib/middleman-core/rack.rb index cf241d9f..293a2e43 100644 --- a/middleman-core/lib/middleman-core/rack.rb +++ b/middleman-core/lib/middleman-core/rack.rb @@ -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 "

File Not Found

#{path}

" res.finish diff --git a/middleman-core/lib/middleman-core/renderers/redcarpet.rb b/middleman-core/lib/middleman-core/renderers/redcarpet.rb index 122de759..1542489c 100644 --- a/middleman-core/lib/middleman-core/renderers/redcarpet.rb +++ b/middleman-core/lib/middleman-core/renderers/redcarpet.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 22213c21..fd236f3f 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -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. diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index a7ade5fc..4667936d 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/util/files.rb b/middleman-core/lib/middleman-core/util/files.rb index f8fb1316..4422b3ef 100644 --- a/middleman-core/lib/middleman-core/util/files.rb +++ b/middleman-core/lib/middleman-core/util/files.rb @@ -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