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