Catch exceptions at Rack level. closes #183
This commit is contained in:
parent
1feea222c0
commit
c48679e993
|
@ -5,12 +5,12 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|||
# Top-level Middleman object
|
||||
module Middleman
|
||||
# Auto-load modules on-demand
|
||||
autoload :Base, "middleman/base"
|
||||
autoload :Cache, "middleman/cache"
|
||||
autoload :Builder, "middleman/builder"
|
||||
autoload :CLI, "middleman/cli"
|
||||
autoload :Templates, "middleman/templates"
|
||||
autoload :Guard, "middleman/guard"
|
||||
autoload :Base, "middleman/base"
|
||||
autoload :Cache, "middleman/cache"
|
||||
autoload :Builder, "middleman/builder"
|
||||
autoload :CLI, "middleman/cli"
|
||||
autoload :Templates, "middleman/templates"
|
||||
autoload :Guard, "middleman/guard"
|
||||
|
||||
# Custom Renderers
|
||||
module Renderers
|
||||
|
@ -57,13 +57,16 @@ module Middleman
|
|||
autoload :Rendering, "middleman/core_extensions/rendering"
|
||||
|
||||
# Compass framework for Sass
|
||||
autoload :Compass, "middleman/core_extensions/compass"
|
||||
autoload :Compass, "middleman/core_extensions/compass"
|
||||
|
||||
# Sprockets 2
|
||||
autoload :Sprockets, "middleman/core_extensions/sprockets"
|
||||
autoload :Sprockets, "middleman/core_extensions/sprockets"
|
||||
|
||||
# Pass custom options to views
|
||||
autoload :Routing, "middleman/core_extensions/routing"
|
||||
|
||||
# Catch and show exceptions at the Rack level
|
||||
autoload :ShowExceptions, "middleman/core_extensions/show_exceptions"
|
||||
end
|
||||
|
||||
module Extensions
|
||||
|
|
|
@ -59,7 +59,17 @@ class Middleman::Base
|
|||
# @return [Rack::Builder]
|
||||
def to_rack_app(&block)
|
||||
inner_app = inst(&block)
|
||||
|
||||
(@middleware || []).each do |m|
|
||||
app.use(m[0], *m[1], &m[2])
|
||||
end
|
||||
|
||||
app.map("/") { run inner_app }
|
||||
|
||||
(@mappings || []).each do |m|
|
||||
app.map(m[0], &m[1])
|
||||
end
|
||||
|
||||
app
|
||||
end
|
||||
|
||||
|
@ -82,14 +92,16 @@ class Middleman::Base
|
|||
#
|
||||
# @param [Class] Middleware
|
||||
def use(middleware, *args, &block)
|
||||
app.use(middleware, *args, &block)
|
||||
@middleware ||= []
|
||||
@middleware << [middleware, args, block]
|
||||
end
|
||||
|
||||
# Add Rack App mapped to specific path
|
||||
#
|
||||
# @param [String] Path to map
|
||||
def map(map, &block)
|
||||
app.map(map, &block)
|
||||
@mappings ||= []
|
||||
@mappings << [map, block]
|
||||
end
|
||||
|
||||
# Mix-in helper methods. Accepts either a list of Modules
|
||||
|
@ -168,6 +180,10 @@ class Middleman::Base
|
|||
# @return [String]
|
||||
set :http_prefix, "/"
|
||||
|
||||
# Whether to catch and display exceptions
|
||||
# @return [Boolean]
|
||||
set :show_exceptions, true
|
||||
|
||||
# Automatically loaded extensions
|
||||
# @return [Array<Symbol>]
|
||||
set :default_extensions, [
|
||||
|
@ -182,6 +198,9 @@ class Middleman::Base
|
|||
# Activate custom features and extensions
|
||||
include Middleman::CoreExtensions::Extensions
|
||||
|
||||
# Handle exceptions
|
||||
register Middleman::CoreExtensions::ShowExceptions
|
||||
|
||||
# Add Builder Callbacks
|
||||
register Middleman::CoreExtensions::Builder
|
||||
|
||||
|
|
16
lib/middleman/core_extensions/show_exceptions.rb
Normal file
16
lib/middleman/core_extensions/show_exceptions.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'rack/showexceptions'
|
||||
|
||||
module Middleman::CoreExtensions::ShowExceptions
|
||||
class << self
|
||||
def registered(app)
|
||||
app.after_configuration do
|
||||
if show_exceptions
|
||||
use ::Middleman::CoreExtensions::ShowExceptions::Middleware
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Middleware < ::Rack::ShowExceptions
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue