Take a bit more care when checking if a view file exists.

This commit is contained in:
David Siegel 2011-06-23 09:32:10 -07:00
parent 621825b36c
commit fe9a5ece32

View file

@ -7,12 +7,12 @@ module Middleman::Features::DefaultHelpers
end end
module Helpers module Helpers
def auto_stylesheet_link_tag(separator="/") def auto_stylesheet_link_tag(separator="/")
auto_tag(:css, separator) do |path| auto_tag(:css, separator) do |path|
stylesheet_link_tag path stylesheet_link_tag path
end end
end end
def auto_javascript_include_tag(separator="/") def auto_javascript_include_tag(separator="/")
auto_tag(:js, separator) do |path| auto_tag(:js, separator) do |path|
javascript_include_tag path javascript_include_tag path
@ -27,15 +27,15 @@ module Middleman::Features::DefaultHelpers
end end
end end
path = request.path_info.dup path = request.path_info.dup
# If the basename of the request as no extension, assume we are serving a # If the basename of the request as no extension, assume we are serving a
# directory and join index_file to the path. # directory and join index_file to the path.
path = File.join(path, self.class.index_file) if File.extname(path).empty? path = File.join(path, self.class.index_file) if File.extname(path).empty?
path = path.gsub(%r{^/}, '') path = path.gsub(%r{^/}, '')
path = path.gsub(File.extname(path), ".#{asset_ext}") path = path.gsub(File.extname(path), ".#{asset_ext}")
path = path.gsub("/", separator) path = path.gsub("/", separator)
views = Dir[File.join(self.class.views, asset_dir, "#{path}*")] view = File.join(self.class.views, asset_dir, path)
yield path if views.any? yield path if File.exists?(view) or Dir["#{view}.*"].any?
end end
def page_classes def page_classes