reenable build reroute
This commit is contained in:
parent
0e5ce50787
commit
0d0eda71c2
6 changed files with 56 additions and 48 deletions
|
@ -5,7 +5,6 @@ require "hooks"
|
|||
require "active_support"
|
||||
require "active_support/json"
|
||||
require "active_support/core_ext/string/inflections"
|
||||
# require "active_support/core_ext/class/attribute_accessors"
|
||||
|
||||
class Middleman::Base
|
||||
include Hooks
|
||||
|
@ -199,22 +198,22 @@ class Middleman::Base
|
|||
|
||||
# Internal method to look for templates and evaluate them if found
|
||||
def process_request
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
@original_path = env["PATH_INFO"].dup
|
||||
@request_path = full_path(env["PATH_INFO"].gsub("%20", " "))
|
||||
|
||||
run_hook :before
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
original_path = env["PATH_INFO"].dup
|
||||
request_path = full_path(env["PATH_INFO"].gsub("%20", " "))
|
||||
|
||||
return not_found if sitemap.ignored_path?(request_path)
|
||||
return not_found if sitemap.ignored_path?(@request_path)
|
||||
|
||||
if sitemap.path_is_proxy?(request_path)
|
||||
request_path = "/" + sitemap.path_target(request_path)
|
||||
if sitemap.path_is_proxy?(@request_path)
|
||||
@request_path = "/" + sitemap.path_target(@request_path)
|
||||
end
|
||||
|
||||
found_template = resolve_template(request_path)
|
||||
found_template = resolve_template(@request_path)
|
||||
return not_found unless found_template
|
||||
|
||||
@current_path = request_path
|
||||
@current_path = @request_path.dup
|
||||
path, engine = found_template
|
||||
|
||||
# Static File
|
||||
|
@ -222,7 +221,7 @@ class Middleman::Base
|
|||
|
||||
return unless self.class.execute_before_processing!(self, found_template)
|
||||
|
||||
context = sitemap.get_context(original_path) || {}
|
||||
context = sitemap.get_context(@original_path) || {}
|
||||
|
||||
@options = context.has_key?(:options) ? context[:options] : {}
|
||||
@locals = context.has_key?(:locals) ? context[:locals] : {}
|
||||
|
@ -234,7 +233,7 @@ class Middleman::Base
|
|||
|
||||
local_layout = if options.has_key?(:layout)
|
||||
options[:layout]
|
||||
elsif %w(.js .css).include?(File.extname(request_path))
|
||||
elsif %w(.js .css).include?(File.extname(@request_path))
|
||||
false
|
||||
else
|
||||
layout
|
||||
|
@ -244,7 +243,7 @@ class Middleman::Base
|
|||
instance_eval(&context[:block])
|
||||
end
|
||||
|
||||
# content_type mime_type(File.extname(request_path))
|
||||
# content_type mime_type(File.extname(@request_path))
|
||||
res.status = 200
|
||||
|
||||
output = if local_layout
|
||||
|
@ -337,7 +336,7 @@ public
|
|||
|
||||
def not_found
|
||||
@res.status == 404
|
||||
@res.write "<html><body><h1>File Not Found</h1><p>#{env["PATH_INFO"]}</p></body>"
|
||||
@res.write "<html><body><h1>File Not Found</h1><p>#{@request_path}</p></body>"
|
||||
@res.finish
|
||||
end
|
||||
|
||||
|
@ -391,7 +390,7 @@ public
|
|||
|
||||
file = ::Rack::File.new nil
|
||||
file.path = path
|
||||
file.serving(env)
|
||||
halt file.serving(env)
|
||||
end
|
||||
|
||||
def render(path, locals = {}, options = {}, &block)
|
||||
|
|
|
@ -18,7 +18,7 @@ module Middleman
|
|||
request_path = destination.sub(/^#{SHARED_SERVER_INST.build_dir}/, "")
|
||||
|
||||
begin
|
||||
# destination, request_path = SHARED_SERVER.reroute_builder(destination, request_path)
|
||||
destination, request_path = SHARED_SERVER_INST.reroute_builder(destination, request_path)
|
||||
|
||||
request_path.gsub!(/\s/, "%20")
|
||||
response = Middleman::Builder.shared_rack.get(request_path)
|
||||
|
@ -43,7 +43,7 @@ module Middleman
|
|||
@shared_rack ||= begin
|
||||
mock = ::Rack::MockSession.new(SHARED_SERVER.to_rack_app)
|
||||
sess = ::Rack::Test::Session.new(mock)
|
||||
response = sess.get("__middleman__")
|
||||
# response = sess.get("__middleman__")
|
||||
sess
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ module Middleman::CoreExtensions::Builder
|
|||
class << self
|
||||
def registered(app)
|
||||
app.extend ClassMethods
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -13,16 +14,25 @@ module Middleman::CoreExtensions::Builder
|
|||
|
||||
def build_reroute(&block)
|
||||
@build_rerouters ||= []
|
||||
@build_rerouters << block
|
||||
@build_rerouters << block if block_given?
|
||||
@build_rerouters
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def after_build(&block)
|
||||
self.class.after_build(&block)
|
||||
end
|
||||
|
||||
def build_reroute(&block)
|
||||
self.class.build_reroute(&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)
|
||||
build_reroute.each do |block|
|
||||
output = instance_exec(desination, request_path, &block)
|
||||
if output
|
||||
result = output
|
||||
break
|
||||
|
|
|
@ -14,7 +14,7 @@ module Middleman::CoreExtensions::Sprockets
|
|||
def registered(app)
|
||||
app.set :js_compressor, false
|
||||
app.set :css_compressor, false
|
||||
|
||||
return
|
||||
# Cut off every extension after .js (which sprockets eats up)
|
||||
app.build_reroute do |destination, request_path|
|
||||
if !request_path.match(/\.js\./i)
|
||||
|
|
|
@ -3,41 +3,42 @@ module Middleman::Features::DirectoryIndexes
|
|||
def registered(app)
|
||||
app.send :include, InstanceMethods
|
||||
app.before do
|
||||
indexed_path = env["PATH_INFO"].sub(/\/$/, "") + "/" + self.index_file
|
||||
prefix = @original_path.sub(/\/$/, "")
|
||||
indexed_path = prefix + "/" + self.index_file
|
||||
indexed_exists = resolve_template(indexed_path)
|
||||
|
||||
extensioned_path = env["PATH_INFO"].sub(/\/$/, "") + File.extname(self.index_file)
|
||||
|
||||
extensioned_path = prefix + File.extname(self.index_file)
|
||||
is_ignored = self.ignored_directory_indexes.include?(extensioned_path)
|
||||
|
||||
if !indexed_exists && !is_ignored
|
||||
parts = env["PATH_INFO"].split("/")
|
||||
parts = @original_path.split("/")
|
||||
last_part = parts.last
|
||||
last_part_ext = File.extname(last_part)
|
||||
|
||||
if last_part_ext.blank?
|
||||
# This is a folder, redirect to index
|
||||
env["PATH_INFO"] = extensioned_path
|
||||
@request_path = extensioned_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# app.build_reroute do |destination, request_path|
|
||||
# index_ext = File.extname(app.settings.index_file)
|
||||
# new_index_path = "/#{app.settings.index_file}"
|
||||
#
|
||||
# indexed_path = request_path.gsub(/\/$/, "") + index_ext
|
||||
#
|
||||
# if app.settings.ignored_directory_indexes.include?(request_path)
|
||||
# false
|
||||
# elsif request_path =~ /#{new_index_path}$/
|
||||
# false
|
||||
# else
|
||||
# [
|
||||
# destination.gsub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
||||
# request_path
|
||||
# ]
|
||||
# end
|
||||
# end
|
||||
app.build_reroute do |destination, request_path|
|
||||
index_ext = File.extname(self.index_file)
|
||||
new_index_path = "/#{self.index_file}"
|
||||
|
||||
indexed_path = request_path.sub(/\/$/, "") + index_ext
|
||||
|
||||
if self.ignored_directory_indexes.include?(request_path)
|
||||
false
|
||||
elsif request_path =~ /#{new_index_path}$/
|
||||
false
|
||||
else
|
||||
[
|
||||
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
||||
request_path
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
|
|
@ -33,12 +33,10 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
||||
s.add_dependency("execjs", ["~> 1.2.7"])
|
||||
s.add_dependency("sprockets", ["~> 2.0"])
|
||||
s.add_dependency("sprockets-sass", ["~> 0.3.0"])
|
||||
s.add_dependency("sprockets-sass", ["~> 0.4.0"])
|
||||
s.add_dependency("hooks", ["~> 0.2.0"])
|
||||
s.add_dependency("rb-fsevent")
|
||||
|
||||
s.add_dependency("guard", ["~> 0.8.8"])
|
||||
# s.add_dependency("eventmachine", ["1.0.0.beta.4"])
|
||||
|
||||
# Development and test
|
||||
s.add_development_dependency("slim")
|
||||
|
|
Loading…
Reference in a new issue