Make custom page/layout rendering handle all possible directory/index permutations. closes #37
This commit is contained in:
parent
f5a009fe44
commit
f8b7f410a6
|
@ -9,4 +9,31 @@ Feature: Custom layouts
|
|||
Scenario: Using with_layout block
|
||||
Given "/custom-layout.html" with_layout block has layout "custom"
|
||||
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"
|
||||
When I go to "/custom-layout-dir"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/index.html"
|
||||
Then I should see "Custom Layout"
|
||||
|
||||
Scenario: Using custom :layout attribute with folders
|
||||
Given page "/custom-layout-dir" has layout "custom"
|
||||
When I go to "/custom-layout-dir"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/index.html"
|
||||
Then I should see "Custom Layout"
|
||||
|
||||
Scenario: Using custom :layout attribute with folders
|
||||
Given page "/custom-layout-dir/index.html" has layout "custom"
|
||||
When I go to "/custom-layout-dir"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/"
|
||||
Then I should see "Custom Layout"
|
||||
When I go to "/custom-layout-dir/index.html"
|
||||
Then I should see "Custom Layout"
|
1
fixtures/test-app/views/custom-layout-dir/index.html.haml
Executable file
1
fixtures/test-app/views/custom-layout-dir/index.html.haml
Executable file
|
@ -0,0 +1 @@
|
|||
%h1 Welcome
|
|
@ -101,12 +101,20 @@ module Middleman
|
|||
# page "/about.html", :layout => false
|
||||
# page "/", :layout => :homepage_layout
|
||||
def self.page(url, options={}, &block)
|
||||
url << settings.index_file if url.match(%r{/$})
|
||||
url = url.gsub(%r{#{settings.index_file}$}, "")
|
||||
url = url.gsub(%r{(\/)$}, "") if url.length > 1
|
||||
|
||||
paths = [url]
|
||||
paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
|
||||
paths << "/#{path_to_index(url)}"
|
||||
|
||||
options[:layout] = current_layout if options[:layout].nil?
|
||||
get(url) do
|
||||
return yield if block_given?
|
||||
process_request(options)
|
||||
|
||||
paths.each do |p|
|
||||
get(p) do
|
||||
return yield if block_given?
|
||||
process_request(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -116,15 +124,18 @@ module Middleman
|
|||
end
|
||||
|
||||
private
|
||||
# Internal method to look for templates and evaluate them if found
|
||||
def process_request(options={})
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
path = request.path
|
||||
def self.path_to_index(path)
|
||||
parts = path ? path.split('/') : []
|
||||
if parts.last.nil? || parts.last.split('.').length == 1
|
||||
path = File.join(path, settings.index_file)
|
||||
end
|
||||
path.gsub!(%r{^/}, '')
|
||||
path.gsub(%r{^/}, '')
|
||||
end
|
||||
|
||||
# Internal method to look for templates and evaluate them if found
|
||||
def process_request(options={})
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
path = self.class.path_to_index(request.path)
|
||||
|
||||
static_path = File.join(Middleman::Server.public, path)
|
||||
# if File.exists? static_path
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Middleman
|
||||
VERSION = "1.1.5"
|
||||
VERSION = "1.1.6"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue