Merb::BootLoader.after_app_loads do
module Merb
class Dispatcher
# :api: private
module DefaultExceptionHelper
# :api: private
def humanize_exception(e)
e.class.name.split("::").last.gsub(/([a-z])([A-Z])/, '\1 \2')
end
# :api: private
def error_codes(exception)
if @show_details
message, message_details = exception.message.split("\n", 2)
"
#{escape_html(message)}
#{escape_html(message_details)}
"
else
"Sorry about that...
"
end
end
# :api: private
def frame_details(line)
if (match = line.match(/^(.+):(\d+):(.+)$/))
filename = match[1]
lineno = match[2]
location = match[3]
if filename.index(Merb.framework_root) == 0
type = "framework"
shortname = Pathname.new(filename).relative_path_from(Pathname.new(Merb.framework_root))
elsif filename.index(Merb.root) == 0
type = "app"
shortname = Pathname.new(filename).relative_path_from(Pathname.new(Merb.root))
elsif path = Gem.path.find {|p| filename.index(p) == 0}
type = "gem"
shortname = Pathname.new(filename).relative_path_from(Pathname.new(path))
else
type = "other"
shortname = filename
end
[type, shortname, filename, lineno, location]
else
['', '', '', nil, nil]
end
end
# :api: private
def listing(key, value, arr)
ret = []
ret << ""
ret << " "
ret << " #{key} | #{value} |
"
ret << " "
ret << " "
(arr || []).each_with_index do |(key, val), i|
klass = i % 2 == 0 ? "even" : "odd"
ret << " #{key} | #{val.inspect} |
"
end
if arr.blank?
ret << " None |
"
end
ret << " "
ret << "
"
ret.join("\n")
end
def jar?(filename)
filename.match(/jar\!/)
end
# :api: private
def textmate_url(filename, line)
"#{line}"
end
# :api: private
def render_source(filename, line)
line = line.to_i
ret = []
ret << ""
ret << " | "
str = " "
__caller_lines__(filename, line, 5) do |lline, lcode|
str << " #{lline}"
str << " " if line == lline
str << Erubis::XmlHelper.escape_xml(lcode)
str << "" if line == lline
str << "\n"
end
str << " | "
ret << str
ret << "
"
ret.join("\n")
end
def jar?(filename)
filename.match(/jar\!/)
end
end
# :api: private
class DefaultException < Merb::Controller
self._template_root = File.dirname(__FILE__) / "views"
# :api: private
def _template_location(context, type = nil, controller = controller_name)
"#{context}.#{type}"
end
# :api: private
def index
@exceptions = request.exceptions
@show_details = Merb::Config[:exception_details]
render :format => :html
end
end
end
end
end