Skip to content

Commit

Permalink
Make with_layout work with globs/regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Mar 15, 2012
1 parent 5db1a94 commit 4a5fede
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 6 additions & 0 deletions middleman-core/features/custom_layouts.feature
Expand Up @@ -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"
Expand Down
16 changes: 6 additions & 10 deletions middleman-core/lib/middleman-core/core_extensions/routing.rb
Expand Up @@ -45,6 +45,9 @@ def with_layout(layout_name, &block)
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?("*")

Expand All @@ -56,9 +59,6 @@ def page(url, opts={}, &block)
return
end

# Default layout
opts[:layout] = layout if opts[:layout].nil?

# Normalized path
url = full_path(url)

Expand All @@ -79,13 +79,9 @@ def page(url, opts={}, &block)
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
Expand Down

0 comments on commit 4a5fede

Please sign in to comment.