From 4a5fededf705e82e76d95beb2512b5abebaffd7b Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Thu, 15 Mar 2012 00:31:50 -0700 Subject: [PATCH] Make with_layout work with globs/regexes --- middleman-core/features/custom_layouts.feature | 6 ++++++ .../middleman-core/core_extensions/routing.rb | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/middleman-core/features/custom_layouts.feature b/middleman-core/features/custom_layouts.feature index afeb7a41..10f127ba 100644 --- a/middleman-core/features/custom_layouts.feature +++ b/middleman-core/features/custom_layouts.feature @@ -12,6 +12,12 @@ Feature: Custom layouts And the Server is running at "custom-layout-app2" When I go to "/custom-layout.html" Then I should see "Custom Layout" + + Scenario: Using with_layout block with globs + Given "/custom-*" with_layout block has layout "custom" + And the Server is running at "custom-layout-app2" + When I go to "/custom-layout.html" + Then I should see "Custom Layout" Scenario: Using custom :layout attribute with folders Given page "/custom-layout-dir/" has layout "custom" diff --git a/middleman-core/lib/middleman-core/core_extensions/routing.rb b/middleman-core/lib/middleman-core/core_extensions/routing.rb index 6be37409..c7ee9c00 100644 --- a/middleman-core/lib/middleman-core/core_extensions/routing.rb +++ b/middleman-core/lib/middleman-core/core_extensions/routing.rb @@ -45,6 +45,9 @@ module Middleman::CoreExtensions::Routing def page(url, opts={}, &block) a_block = block_given? ? block : nil + # Default layout + opts[:layout] = layout if opts[:layout].nil? + # If the url is a regexp if url.is_a?(Regexp) || url.include?("*") @@ -56,9 +59,6 @@ module Middleman::CoreExtensions::Routing return end - # Default layout - opts[:layout] = layout if opts[:layout].nil? - # Normalized path url = full_path(url) @@ -79,13 +79,9 @@ module Middleman::CoreExtensions::Routing end end - # If we have a block or opts - if a_block || !opts.empty? - - # Setup a metadata matcher for rendering those options - provides_metadata_for_path url do |url| - { :options => opts, :blocks => [a_block] } - end + # Setup a metadata matcher for rendering those options + provides_metadata_for_path url do |url| + { :options => opts, :blocks => [a_block] } end end end