fix double-run layout lookup

This commit is contained in:
Thomas Reynolds 2011-11-25 16:25:02 -08:00
parent fee6fba15d
commit 2b545f8e35

View file

@ -120,17 +120,23 @@ module Middleman::Sitemap
end end
def locate_layout(name, preferred_engine=nil) def locate_layout(name, preferred_engine=nil)
# Check root layout_path = false
layout_path, *etc = resolve_template(name, :preferred_engine => preferred_engine)
if !preferred_engine.nil?
# Check root
layout_path, *etc = resolve_template(name, :preferred_engine => preferred_engine)
# Check layouts folder # Check layouts folder
if !layout_path if !layout_path
layout_path, *etc = resolve_template(File.join("layouts", name.to_s), :preferred_engine => preferred_engine) layout_path, *etc = resolve_template(File.join("layouts", name.to_s), :preferred_engine => preferred_engine)
end
end end
# Check root, no preference # Check root, no preference
layout_path, *etc = resolve_template(name) if !layout_path
layout_path, *etc = resolve_template(name)
end
# Check layouts folder, no preference # Check layouts folder, no preference
if !layout_path if !layout_path
layout_path, *etc = resolve_template(File.join("layouts", name.to_s)) layout_path, *etc = resolve_template(File.join("layouts", name.to_s))
@ -145,7 +151,9 @@ module Middleman::Sitemap
relative_path = request_path.sub(%r{^/}, "") relative_path = request_path.sub(%r{^/}, "")
on_disk_path = File.expand_path(relative_path, app.source_dir) on_disk_path = File.expand_path(relative_path, app.source_dir)
preferred_engine = if options.has_key?(:preferred_engine) preferred_engine = "*"
if options.has_key?(:preferred_engine)
extension_class = ::Tilt[options[:preferred_engine]] extension_class = ::Tilt[options[:preferred_engine]]
matched_exts = [] matched_exts = []
@ -155,25 +163,24 @@ module Middleman::Sitemap
matched_exts << ext matched_exts << ext
end end
"{" + matched_exts.join(",") + "}" if matched_exts.length > 0
else preferred_engine = "{" + matched_exts.join(",") + "}"
"*" else
return false
end
end end
path_with_ext = on_disk_path + "." + preferred_engine path_with_ext = on_disk_path + "." + preferred_engine
found_path = Dir[path_with_ext].find do |path| found_path = Dir[path_with_ext].find do |path|
::Tilt[path] ::Tilt[path]
end end
result = if found_path || File.exists?(on_disk_path) if found_path || File.exists?(on_disk_path)
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
[ found_path || on_disk_path, engine ] [ found_path || on_disk_path, engine ]
else else
false false
end end
result
end end
end end