Module: Merb::Dispatcher::DefaultExceptionHelper

Defined in:
lib/merb-core/dispatch/default_exception/default_exception.rb

Instance Method Summary collapse

Instance Method Details

#error_codes(exception) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 8

def error_codes(exception)
  if @show_details
    message, message_details = exception.message.split("\n", 2)
    "<h2>#{html_escape(message)}</h2><p>#{html_escape(message_details)}</p>"
  else
    "<h2>Sorry about that...</h2>"
  end
end

#frame_details(line) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 17

def frame_details(line)
  filename, lineno, location = line.split(":")
  if filename.index(Merb.framework_root)
    type = "framework"
    shortname = Pathname.new(filename).relative_path_from(Pathname.new(Merb.framework_root))
  elsif filename.index(Merb.root)
    type = "app"
    shortname = Pathname.new(filename).relative_path_from(Pathname.new(Merb.root))
  elsif path = Gem.path.find {|p| filename.index(p)}
    type = "gem"
    shortname = Pathname.new(filename).relative_path_from(Pathname.new(path))
  else
    type = "other"
    shortname = filename
  end
  [type, shortname, filename, lineno, location]
end

#humanize_exception(e) ⇒ Object



4
5
6
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 4

def humanize_exception(e)
  e.class.name.split("::").last.gsub(/([a-z])([A-Z])/, '\1 \2')
end

#listing(key, value, arr) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 35

def listing(key, value, arr)
  ret   =  []
  ret   << "<table class=\"listing\" style=\"display: none\">"
  ret   << "  <thead>"
  ret   << "    <tr><th width='25%'>#{key}</th><th width='75%'>#{value}</th></tr>"
  ret   << "  </thead>"
  ret   << "  <tbody>"
  (arr || []).each_with_index do |(key, val), i|
    klass = i % 2 == 0 ? "even" : "odd"
    ret << "    <tr class=#{klass}><td>#{key}</td><td>#{val.inspect}</td></tr>"
  end
  if arr.blank?
    ret << "    <tr class='odd'><td colspan='2'>None</td></tr>"
  end
  ret   << "  </tbody>"
  ret   << "</table>"
  ret.join("\n")
end

#render_source(filename, line) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 58

def render_source(filename, line)
  line = line.to_i
  ret   =  []
  ret   << "<tr class='source'>"
  ret   << "  <td class='collapse'></td>"
  str   =  "  <td class='code' colspan='2'><div>"
  
  __caller_lines__(filename, line, 5) do |lline, lcode|
    str << "<a href='txmt://open?url=file://#{filename}&amp;line=#{lline}'>#{lline}</a>"
    str << "<em>" if line == lline
    str << Erubis::XmlHelper.escape_xml(lcode)
    str << "</em>" if line == lline
    str << "\n"
  end
  str   << "</div></td>"
  ret   << str
  ret   << "</tr>"
  ret.join("\n")
end

#textmate_url(filename, line) ⇒ Object



54
55
56
# File 'lib/merb-core/dispatch/default_exception/default_exception.rb', line 54

def textmate_url(filename, line)
  "<a href='txmt://open?url=file://#{filename}&amp;line=#{line}'>#{line}</a>"
end