Class: Rackr::Router::Errors::DevHtml
- Inherits:
-
Object
- Object
- Rackr::Router::Errors::DevHtml
show all
- Includes:
- Action, HTML
- Defined in:
- lib/rackr/router/errors/dev_html.rb
Instance Method Summary
collapse
Methods included from HTML
included
Methods included from Action
#erb, #head, #head_response, #html, #html_response, included, #json, #json_response, #load_json, #redirect_response, #redirect_to, #response, #text, #text_response
Instance Method Details
#backtrace(env) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rackr/router/errors/dev_html.rb', line 48
def backtrace(env)
first, *tail = env['error'].backtrace
h2 do
_ 'Traceback '
span '(innermost first)'
end
tag :p, first, class: 'first-p'
br
line_number = (first)
match = first.match(%r{^(/[\w/.-]+)})
file_path = (match ? match[1] : nil)
unless file_path.nil?
lines = []
File.open(file_path) do |file|
lines = file.readlines
end
lines.map!.with_index do |line, i|
"#{i + 1}: #{line} \n"
end
tag :pre, slice_around_index(lines, line_number).join('').chomp
end
tag :p, tail.join("\n")
end
|
#call(env) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rackr/router/errors/dev_html.rb', line 10
def call(env)
html do
tag :head do
title 'Application error'
_ '<style>
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; }
h2 { margin-bottom:.8em; }
h2 span { font-size:80%; color:#666; font-weight:normal; }
#summary { background: #ffc; }
#summary h2 { font-weight: normal; color: #666; }
pre {
background: #f8f8f8;
padding: 1em;
margin-bottom: 1em;
}
</style>'
end
tag :body do
div id: 'summary' do
h1 env['error'].class.to_s
if env['error'].message.size > 1000
h2 "#{env['error'].message.slice(0, 1000)} ..."
else
h2 env['error'].message
end
end
div id: 'backtrace' do
backtrace(env)
end
end
end
end
|
77
78
79
80
81
|
# File 'lib/rackr/router/errors/dev_html.rb', line 77
def (input)
if (match = input.match(/:(\d+):in/))
match[1].to_i
end
end
|
#slice_around_index(array, index) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/rackr/router/errors/dev_html.rb', line 83
def slice_around_index(array, index)
return array if index.nil? || index < 1
index -= 1
start_index = [index - 2, 0].max
end_index = [index + 2, array.size - 1].min
array[start_index..end_index]
end
|