Merge pull request #601 from bhollis/full_path
Fix previewing directories with '.' in them.
This commit is contained in:
commit
a8a555c101
|
@ -183,11 +183,7 @@ module Middleman
|
|||
# Evaluate a passed block if given
|
||||
instance_exec(&block) if block_given?
|
||||
|
||||
# Build expanded source path once paths have been parsed
|
||||
path = root.dup
|
||||
source_path = ENV["MM_SOURCE"] || self.source
|
||||
path = File.join(root, source_path) unless source_path.empty?
|
||||
set :source_dir, path
|
||||
set :source, ENV["MM_SOURCE"] if ENV["MM_SOURCE"]
|
||||
|
||||
super
|
||||
end
|
||||
|
@ -216,6 +212,13 @@ module Middleman
|
|||
self
|
||||
end
|
||||
|
||||
# The full path to the source directory
|
||||
#
|
||||
# @return [String]
|
||||
def source_dir
|
||||
File.join(root, source)
|
||||
end
|
||||
|
||||
delegate :logger, :instrument, :to => ::Middleman::Util
|
||||
|
||||
# Work around this bug: http://bugs.ruby-lang.org/issues/4521
|
||||
|
@ -232,12 +235,18 @@ module Middleman
|
|||
# @param [String] path Request path
|
||||
# @return [String] Path with index file if necessary
|
||||
def full_path(path)
|
||||
cache.fetch(:full_path, path) do
|
||||
parts = path ? path.split('/') : []
|
||||
if parts.last.nil? || parts.last.split('.').length == 1
|
||||
path = File.join(path, index_file)
|
||||
resource = sitemap.find_resource_by_destination_path(path)
|
||||
|
||||
if !resource
|
||||
# Try it with /index.html at the end
|
||||
indexed_path = File.join(path.sub(%r{/$}, ''), index_file)
|
||||
resource = sitemap.find_resource_by_destination_path(indexed_path)
|
||||
end
|
||||
"/" + path.sub(%r{^/}, '')
|
||||
|
||||
if resource
|
||||
'/' + resource.destination_path
|
||||
else
|
||||
'/' + Middleman::Util.normalize_path(path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -227,32 +227,26 @@ module Middleman
|
|||
start_time = Time.now
|
||||
@current_path = nil
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
original_path = URI.decode(env["PATH_INFO"].dup)
|
||||
if original_path.respond_to? :force_encoding
|
||||
original_path.force_encoding('UTF-8')
|
||||
request_path = URI.decode(env["PATH_INFO"].dup)
|
||||
if request_path.respond_to? :force_encoding
|
||||
request_path.force_encoding('UTF-8')
|
||||
end
|
||||
request_path = full_path(original_path)
|
||||
request_path = full_path(request_path)
|
||||
|
||||
# Run before callbacks
|
||||
run_hook :before
|
||||
|
||||
if original_path != request_path
|
||||
# Get the resource object for this path
|
||||
resource = sitemap.find_resource_by_destination_path(original_path)
|
||||
end
|
||||
|
||||
# Get the resource object for this full path
|
||||
resource ||= sitemap.find_resource_by_destination_path(request_path)
|
||||
resource = sitemap.find_resource_by_destination_path(request_path)
|
||||
|
||||
# Return 404 if not in sitemap
|
||||
return not_found(res) unless resource && !resource.ignored?
|
||||
return not_found(res, request_path) unless resource && !resource.ignored?
|
||||
|
||||
current_path = resource.destination_path
|
||||
|
||||
# If this path is a static file, send it immediately
|
||||
return send_file(resource.source_file, env, res) unless resource.template?
|
||||
|
||||
current_path = request_path.dup
|
||||
|
||||
# Set a HTTP content type based on the request's extensions
|
||||
content_type(res, resource.mime_type)
|
||||
|
||||
|
@ -272,7 +266,7 @@ module Middleman
|
|||
end
|
||||
|
||||
# End the request
|
||||
logger.debug "== Finishing Request: #{request_path} (#{(Time.now - start_time).round(2)}s)"
|
||||
logger.debug "== Finishing Request: #{current_path} (#{(Time.now - start_time).round(2)}s)"
|
||||
halt res.finish
|
||||
end
|
||||
|
||||
|
@ -289,9 +283,9 @@ module Middleman
|
|||
end
|
||||
|
||||
# Halt request and return 404
|
||||
def not_found(res)
|
||||
def not_found(res, path)
|
||||
res.status == 404
|
||||
res.write "<html><body><h1>File Not Found</h1><p>#{@request_path}</p></body>"
|
||||
res.write "<html><body><h1>File Not Found</h1><p>#{path}</p></body>"
|
||||
res.finish
|
||||
end
|
||||
|
||||
|
|
|
@ -64,7 +64,10 @@ module Middleman
|
|||
end
|
||||
|
||||
# Normalized path
|
||||
url = full_path(url)
|
||||
url = '/' + Middleman::Util.normalize_path(url)
|
||||
if url.end_with?('/') || File.directory?(File.join(source_dir, url))
|
||||
url = File.join(url, index_file)
|
||||
end
|
||||
|
||||
# Setup proxy
|
||||
if opts.has_key?(:proxy)
|
||||
|
|
|
@ -29,20 +29,18 @@ module Middleman
|
|||
module Helpers
|
||||
# Output a stylesheet link tag based on the current path
|
||||
#
|
||||
# @param [String] separator How to break up path in parts
|
||||
# @return [String]
|
||||
def auto_stylesheet_link_tag(separator="/")
|
||||
auto_tag(:css, separator) do |path|
|
||||
def auto_stylesheet_link_tag
|
||||
auto_tag(:css) do |path|
|
||||
stylesheet_link_tag path
|
||||
end
|
||||
end
|
||||
|
||||
# Output a javascript tag based on the current path
|
||||
#
|
||||
# @param [String] separator How to break up path in parts
|
||||
# @return [String]
|
||||
def auto_javascript_include_tag(separator="/")
|
||||
auto_tag(:js, separator) do |path|
|
||||
def auto_javascript_include_tag
|
||||
auto_tag(:js) do |path|
|
||||
javascript_include_tag path
|
||||
end
|
||||
end
|
||||
|
@ -53,7 +51,7 @@ module Middleman
|
|||
# @param [String] separator How to break up path in parts
|
||||
# @param [String] asset_dir Where to look for assets
|
||||
# @return [void]
|
||||
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
||||
def auto_tag(asset_ext, asset_dir=nil)
|
||||
if asset_dir.nil?
|
||||
asset_dir = case asset_ext
|
||||
when :js then js_dir
|
||||
|
@ -63,12 +61,10 @@ module Middleman
|
|||
|
||||
# If the basename of the request as no extension, assume we are serving a
|
||||
# directory and join index_file to the path.
|
||||
path = full_path(current_path.dup)
|
||||
path = path.sub(%r{^/}, '')
|
||||
path = File.join(asset_dir, current_path)
|
||||
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
||||
path = path.gsub("/", separator)
|
||||
|
||||
yield path if sitemap.find_resource_by_path(File.join(asset_dir, path))
|
||||
yield path if sitemap.find_resource_by_path(path)
|
||||
end
|
||||
|
||||
# Generate body css classes based on the current path
|
||||
|
|
Loading…
Reference in a new issue