directory_indexes feature, some builder rename middleware and a bunch of test case cleanup. closes #63
This commit is contained in:
parent
c35a6fc369
commit
5602e35c88
38 changed files with 231 additions and 104 deletions
|
@ -149,6 +149,9 @@ module Middleman
|
|||
|
||||
# Automatically resize images for mobile devises
|
||||
# autoload :TinySrc, "middleman/features/tiny_src"
|
||||
|
||||
# Automatically convert filename.html files into filename/index.html
|
||||
autoload :DirectoryIndexes, "middleman/features/directory_indexes"
|
||||
end
|
||||
|
||||
def self.server(&block)
|
||||
|
|
|
@ -86,7 +86,9 @@ module Middleman::Base
|
|||
request_path = request.path_info.gsub("%20", " ")
|
||||
result = resolve_template(request_path, :raise_exceptions => false)
|
||||
|
||||
if result
|
||||
should_be_ignored = !(request["is_proxy"]) && settings.excluded_paths.include?("/#{request_path}")
|
||||
|
||||
if result && !should_be_ignored
|
||||
extensionless_path, template_engine = result
|
||||
|
||||
# Return static files
|
||||
|
@ -119,6 +121,27 @@ module Middleman::Base
|
|||
super(option, value, &nil)
|
||||
end
|
||||
|
||||
def build_reroute(&block)
|
||||
@build_rerouters ||= []
|
||||
@build_rerouters << block
|
||||
end
|
||||
|
||||
def reroute_builder(desination, request_path)
|
||||
@build_rerouters ||= []
|
||||
|
||||
result = [desination, request_path]
|
||||
|
||||
@build_rerouters.each do |block|
|
||||
output = block.call(desination, request_path)
|
||||
if output
|
||||
result = output
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def before_processing(&block)
|
||||
@before_processes ||= []
|
||||
@before_processes << block
|
||||
|
|
|
@ -15,11 +15,15 @@ module Middleman
|
|||
context = instance_eval('binding')
|
||||
|
||||
request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "")
|
||||
return if SHARED_SERVER.excluded_paths.include?(request_path)
|
||||
|
||||
create_file destination, nil, config do
|
||||
Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
|
||||
Middleman::Builder.shared_rack.last_response.body
|
||||
begin
|
||||
destination, request_page = SHARED_SERVER.reroute_builder(destination, request_path)
|
||||
|
||||
create_file destination, nil, config do
|
||||
Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
|
||||
Middleman::Builder.shared_rack.last_response.body
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,10 @@ module Middleman::CoreExtensions::Routing
|
|||
app.set :proxied_paths, {}
|
||||
app.set :excluded_paths, []
|
||||
|
||||
app.build_reroute do |destination, request_path|
|
||||
throw if app.settings.excluded_paths.include?(request_path)
|
||||
end
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
app.before_processing do
|
||||
request.path_info = self.class.path_to_index(request.path)
|
||||
|
@ -39,7 +43,7 @@ module Middleman::CoreExtensions::Routing
|
|||
end
|
||||
|
||||
def paths_for_url(url)
|
||||
url = url.gsub(%r{#{settings.index_file}$}, "")
|
||||
url = url.gsub(%r{\/#{settings.index_file}$}, "")
|
||||
url = url.gsub(%r{(\/)$}, "") if url.length > 1
|
||||
|
||||
paths = [url]
|
||||
|
@ -76,6 +80,7 @@ module Middleman::CoreExtensions::Routing
|
|||
paths_for_url(url).each do |p|
|
||||
get(p) do
|
||||
if settings.proxied_paths.has_key?(url)
|
||||
request["is_proxy"] = true
|
||||
request.path_info = settings.proxied_paths[url]
|
||||
end
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ module Middleman
|
|||
end
|
||||
|
||||
app.get("/#{app.blog_permalink}") do
|
||||
$stderr.puts "*" * 500
|
||||
process_request({
|
||||
:layout => app.blog_layout,
|
||||
:layout_engine => app.blog_layout_engine
|
||||
|
|
47
lib/middleman/features/directory_indexes.rb
Normal file
47
lib/middleman/features/directory_indexes.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
module Middleman::Features::DirectoryIndexes
|
||||
class << self
|
||||
def registered(app)
|
||||
app.set :ignored_directory_indexes, []
|
||||
app.extend ClassMethods
|
||||
|
||||
app.build_reroute do |destination, request_path|
|
||||
indexed_path = request_path.gsub(/\/$/, "") + ".html"
|
||||
|
||||
if app.settings.ignored_directory_indexes.include?(request_path)
|
||||
false
|
||||
else
|
||||
[
|
||||
destination.gsub(/\.html$/, "/index.html"),
|
||||
request_path.gsub(/\.html$/, "/index.html")
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
app.before do
|
||||
indexed_path = request.path_info.gsub(/\/$/, "") + ".html"
|
||||
|
||||
if !settings.ignored_directory_indexes.include?(indexed_path)
|
||||
parts = request.path_info.split("/")
|
||||
last_part = parts.last
|
||||
last_part_ext = File.extname(last_part)
|
||||
|
||||
if last_part_ext.blank?
|
||||
# This is a folder, redirect to index
|
||||
request.path_info = indexed_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def page(url, options={}, &block)
|
||||
if options.has_key?(:directory_index) && !options["directory_index"]
|
||||
settings.ignored_directory_indexes << url
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue