code_buddy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +44 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +10 -0
  8. data/bin/code_buddy +5 -0
  9. data/code_buddy.gemspec +31 -0
  10. data/lib/code_buddy.rb +12 -0
  11. data/lib/code_buddy/app.rb +50 -0
  12. data/lib/code_buddy/middleware.rb +45 -0
  13. data/lib/code_buddy/public/images/buddy.jpeg +0 -0
  14. data/lib/code_buddy/public/javascripts/backbone.js +966 -0
  15. data/lib/code_buddy/public/javascripts/code_buddy.js +130 -0
  16. data/lib/code_buddy/public/javascripts/jquery.js +7179 -0
  17. data/lib/code_buddy/public/javascripts/underscore.js +722 -0
  18. data/lib/code_buddy/public/stylesheets/code_buddy.css +106 -0
  19. data/lib/code_buddy/public/stylesheets/coderay.css +102 -0
  20. data/lib/code_buddy/stack.rb +19 -0
  21. data/lib/code_buddy/stack_frame.rb +43 -0
  22. data/lib/code_buddy/templates/rescues/_request_and_response.erb +31 -0
  23. data/lib/code_buddy/templates/rescues/_trace.erb +26 -0
  24. data/lib/code_buddy/templates/rescues/diagnostics.erb +10 -0
  25. data/lib/code_buddy/templates/rescues/layout.erb +29 -0
  26. data/lib/code_buddy/templates/rescues/missing_template.erb +2 -0
  27. data/lib/code_buddy/templates/rescues/routing_error.erb +10 -0
  28. data/lib/code_buddy/templates/rescues/template_error.erb +21 -0
  29. data/lib/code_buddy/templates/rescues/unknown_action.erb +2 -0
  30. data/lib/code_buddy/version.rb +3 -0
  31. data/lib/code_buddy/views/banner.erb +6 -0
  32. data/lib/code_buddy/views/form.erb +13 -0
  33. data/lib/code_buddy/views/header.erb +8 -0
  34. data/lib/code_buddy/views/index.erb +25 -0
  35. data/lib/code_buddy/views/orig.erb +53 -0
  36. data/spec/app_spec.rb +6 -0
  37. data/spec/middleware_spec.rb +37 -0
  38. data/spec/spec_helper.rb +26 -0
  39. data/spec/stack_frame_spec.rb +105 -0
  40. data/spec/stack_spec.rb +26 -0
  41. metadata +203 -0
@@ -0,0 +1,106 @@
1
+ html {
2
+ font-family: Monaco;
3
+ color: #E6E0DB;
4
+ font-size:0.95em;
5
+ font-color: white;
6
+ background-color: #333333;
7
+ }
8
+
9
+ body {
10
+ margin: 0;
11
+ }
12
+
13
+ .banner {
14
+ background-color: #222222;
15
+ width: 100%;
16
+ height: 100px;
17
+ position: fixed;
18
+ z-index:10;
19
+ }
20
+
21
+ .buddy {
22
+ float: left;
23
+ padding: 5px;
24
+ }
25
+
26
+ .item {
27
+ float: left;
28
+ }
29
+
30
+ .link {
31
+ float: right;
32
+ padding: 5px;
33
+ }
34
+
35
+ .title {
36
+ font-size:1.95em;
37
+ }
38
+
39
+ .form {
40
+ position: fixed;
41
+ top:100px;
42
+ padding: 10px;
43
+ }
44
+
45
+ a {
46
+ color: white;
47
+ font-size:0.85em;
48
+ }
49
+
50
+ #legend {
51
+ top:100;
52
+ font-size: 0.8em;
53
+ z-index:10;
54
+ position: fixed;
55
+ padding: 5px;
56
+ background-color: #222222;
57
+ }
58
+ #code {
59
+ min-height: 340px;
60
+ border-style: ridge;
61
+ border-color: #666666;
62
+ background-color: black;
63
+ position: fixed;
64
+ top:200;
65
+ width:80%;
66
+ opacity:0.8;
67
+ z-index:10;
68
+ white-space: pre;
69
+ }
70
+ #selected_line {
71
+ border-style: ridge;
72
+ border-color: #666666;
73
+ background-color: black;
74
+ position: fixed;
75
+ top:180;
76
+ width:80%;
77
+ opacity:0.8;
78
+ z-index:10;
79
+ font-size: 12px;
80
+ }
81
+
82
+ #stack {
83
+ position: absolute;
84
+ right:5px;
85
+ top:100px;
86
+ z-index:1;
87
+ text-align: right;
88
+ font-size: 0.8em;
89
+ }
90
+
91
+ .hidden {
92
+ display: none;
93
+ }
94
+
95
+ ul {
96
+ margin-left: 0;
97
+ padding-left: 0;
98
+ }
99
+
100
+ li {
101
+ border-color: #666666;
102
+ font-size: 12px;
103
+ font-family: Monaco;
104
+ line-height: 23px;
105
+ list-style: none;
106
+ }
@@ -0,0 +1,102 @@
1
+ .CodeRay {
2
+ background-color: black;
3
+ border: 1px solid black;
4
+ color: #E6E0DB;
5
+ overflow: auto;
6
+ font-size: 12px;
7
+ }
8
+ .CodeRay pre {
9
+ margin: 0px;
10
+ padding: 0px;
11
+ font-family: Monaco;
12
+ }
13
+
14
+ .CodeRay .an { color:#E7BE69 } /* html attribute */
15
+ .CodeRay .c { color:#AF1CD4; } /* comment */
16
+ .CodeRay .ch { color:#509E4F } /* escaped character */
17
+ .CodeRay .cl { color:#A9A871 } /* class */
18
+ .CodeRay .co { color:#FFF } /* constant */
19
+ .CodeRay .fl { color:#A4C260 } /* float */
20
+ .CodeRay .fu { color:#F7CD00 } /* function */
21
+ .CodeRay .gv { color:#D0CFFE } /* global variable */
22
+ .CodeRay .i { color:#009C9B } /* integer */
23
+ .CodeRay .il { background:#151515 } /* inline code */
24
+ .CodeRay .iv { color:#F7CD00 } /* instance variable */
25
+ .CodeRay .pp { color:#E7BE69 } /* doctype */
26
+ .CodeRay .r { color:#FF5C00 } /* keyword */
27
+ .CodeRay .kw { color:#FF5C00 } /* keyword */
28
+ .CodeRay .rx { color:#009C9B } /* regex */
29
+ .CodeRay .s { color:#00FF00 } /* string */
30
+ .CodeRay .sy { color:#009C9B } /* symbol */
31
+ .CodeRay .ta { color:#E7BE69 } /* html tag */
32
+ .CodeRay .pc { color:#6C9CBD } /* boolean */
33
+
34
+ .selected .overlay {
35
+ position: absolute;
36
+ top: 0;
37
+ bottom: 0;
38
+ left: 0;
39
+ width: 100%;
40
+ /* background: #56547A; */
41
+ background: #CCCCFF;
42
+ opacity: 0.35;
43
+ -moz-opacity: 0.35;
44
+ filter:alpha(opacity=35);
45
+ }
46
+ .container {
47
+ position: relative;
48
+ /* float: left; */
49
+ }
50
+
51
+ #shadow {
52
+ width: 600px;
53
+ position: relative;
54
+ border-right: 1px solid #aaa;
55
+ border-bottom: 1px solid #aaa;
56
+ background: #666666;
57
+ }
58
+ #bodyblock {
59
+ width: 600px;
60
+ position: relative;
61
+ top: -3px;
62
+ left: -3px;
63
+ border-right: 1px solid #666666;
64
+ border-bottom: 1px solid #666666;
65
+ text-align: left;
66
+ color: #666;
67
+ background: #ff9966;
68
+ }
69
+ #header {
70
+ width: 600px;
71
+ height: 20px;
72
+ text-align: left;
73
+ background: #c0c0c0;
74
+ line-height: 20px;
75
+ font-family: Monaco;
76
+ font-size: 10px;
77
+ }
78
+ #header_left {
79
+ width: 300px;
80
+ float: left;
81
+ text-align: left;
82
+ }
83
+ #header_right {
84
+ width: 300px;
85
+ float: right;
86
+ text-align: right;
87
+ vertical-align: middle;
88
+ }
89
+ #header_right a.icon {
90
+ background:url(/images/right.png);
91
+ display:block;
92
+ float:right;
93
+ width:20px;
94
+ height:20px;
95
+ }
96
+ #header_left a.icon {
97
+ background:url(/images/left.png);
98
+ display:block;
99
+ float:left;
100
+ width:20px;
101
+ height:20px;
102
+ }
@@ -0,0 +1,19 @@
1
+ module CodeBuddy
2
+ class Stack
3
+ attr_reader :stack_frames
4
+ attr_accessor :selected
5
+
6
+ def initialize(exception_or_string)
7
+ if exception_or_string.is_a?(Exception)
8
+ @selected = selected
9
+ @stack_frames = exception_or_string.backtrace.collect do |string|
10
+ StackFrame.new(string)
11
+ end
12
+ else
13
+ @stack_frames = exception_or_string.collect do |string|
14
+ StackFrame.new(string)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ module CodeBuddy
2
+ class StackFrame
3
+
4
+ CODE_WINDOW = 10
5
+
6
+ attr_reader :path
7
+ attr_reader :line
8
+
9
+ def initialize(exception_string)
10
+ if exception_string =~ /\s*([^:\s]+):([0-9]+)\s*/
11
+ @path = $1
12
+ @line = $2.to_i
13
+ else
14
+ @path = exception_string
15
+ @line = 0
16
+ end
17
+ code
18
+ end
19
+
20
+ def code
21
+ @code ||= begin
22
+ html_args = { :line_numbers => :inline, :wrap => :span }
23
+ lines_of_code = File.new(path).readlines
24
+
25
+ first_line_to_show = [1, line-CODE_WINDOW].max
26
+ last_line_to_show = [lines_of_code.length, line + 1 + CODE_WINDOW].min
27
+ code_to_show = lines_of_code[first_line_to_show-1 .. last_line_to_show-1]
28
+ formatted_lines = CodeRay.scan(code_to_show, :ruby).
29
+ html(:line_numbers => :inline,
30
+ :wrap => :span,
31
+ :bold_every => false,
32
+ :line_number_start => first_line_to_show)
33
+
34
+ highlighted_line = line - first_line_to_show + 1
35
+ formatted_lines_array = formatted_lines.split("\n")
36
+ formatted_lines_array[highlighted_line-1] = "<span class='container selected'>#{formatted_lines_array[highlighted_line-1]}<span class='overlay'></span></span>"
37
+ formatted_lines_array.join("\n")
38
+ rescue => exception
39
+ "<span class=\"coderay\">Unable to read file:\n&nbsp;\"#{@path}\"</span>"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ <% unless @exception.blamed_files.blank? %>
2
+ <% if (hide = @exception.blamed_files.length > 8) %>
3
+ <a href="#" onclick="document.getElementById('blame_trace').style.display='block'; return false;">Show blamed files</a>
4
+ <% end %>
5
+ <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%=h @exception.describe_blame %></code></pre>
6
+ <% end %>
7
+
8
+ <%
9
+ clean_params = @request.filtered_parameters.clone
10
+ clean_params.delete("action")
11
+ clean_params.delete("controller")
12
+
13
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
14
+
15
+ def debug_hash(hash)
16
+ hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
17
+ end
18
+ %>
19
+
20
+ <h2 style="margin-top: 30px">Request</h2>
21
+ <p><b>Parameters</b>: <pre><%=h request_dump %></pre></p>
22
+
23
+ <p><a href="#" onclick="document.getElementById('session_dump').style.display='block'; return false;">Show session dump</a></p>
24
+ <div id="session_dump" style="display:none"><pre><%= debug_hash @request.session %></pre></div>
25
+
26
+ <p><a href="#" onclick="document.getElementById('env_dump').style.display='block'; return false;">Show env dump</a></p>
27
+ <div id="env_dump" style="display:none"><pre><%= debug_hash @request.env %></pre></div>
28
+
29
+
30
+ <h2 style="margin-top: 30px">Response</h2>
31
+ <p><b>Headers</b>: <pre><%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p>
@@ -0,0 +1,26 @@
1
+ <%
2
+ traces = [
3
+ ["Application Trace", @application_trace],
4
+ ["Framework Trace", @framework_trace],
5
+ ["Full Trace", @full_trace]
6
+ ]
7
+ names = traces.collect {|name, trace| name}
8
+ %>
9
+
10
+ <p><code>Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %></code></p>
11
+
12
+ <div id="traces">
13
+ <% names.each do |name| %>
14
+ <%
15
+ show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';"
16
+ hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"}
17
+ %>
18
+ <a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
19
+ <% end %>
20
+
21
+ <% traces.each do |name, trace| %>
22
+ <div id="<%= name.gsub /\s/, '-' %>" style="display: <%= name == "Application Trace" ? 'block' : 'none' %>;">
23
+ <pre><code><%= trace.enum_with_index.collect { |line, index| link_to line, "code_buddy/#{index}" }.join("\n").html_safe -%></code></pre>
24
+ </div>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,10 @@
1
+ <h1>
2
+ <%=h @exception.class.to_s %>
3
+ <% if @request.parameters['controller'] %>
4
+ in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %>
5
+ <% end %>
6
+ </h1>
7
+ <pre><%=h @exception.message %></pre>
8
+
9
+ <%= render :file => "rescues/_trace.erb" %>
10
+ <%= render :file => "rescues/_request_and_response.erb" %>
@@ -0,0 +1,29 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml">
2
+ <head>
3
+ <title>Action Controller: Exception caught</title>
4
+ <style>
5
+ body { background-color: #fff; color: #333; }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a { color: #000; }
20
+ a:visited { color: #666; }
21
+ a:hover { color: #fff; background-color:#000; }
22
+ </style>
23
+ </head>
24
+ <body>
25
+
26
+ <%= yield %>
27
+
28
+ </body>
29
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Template is missing</h1>
2
+ <p><%=h @exception.message %></p>
@@ -0,0 +1,10 @@
1
+ <h1>Routing Error</h1>
2
+ <p><pre><%=h @exception.message %></pre></p>
3
+ <% unless @exception.failures.empty? %><p>
4
+ <h2>Failure reasons:</h2>
5
+ <ol>
6
+ <% @exception.failures.each do |route, reason| %>
7
+ <li><code><%=h route.inspect.gsub('\\', '') %></code> failed because <%=h reason.downcase %></li>
8
+ <% end %>
9
+ </ol>
10
+ </p><% end %>
@@ -0,0 +1,21 @@
1
+ <h1>
2
+ <%=h @exception.original_exception.class.to_s %> in
3
+ <%=h @request.parameters["controller"].capitalize if @request.parameters["controller"]%>#<%=h @request.parameters["action"] %>
4
+ </h1>
5
+
6
+ <p>
7
+ Showing <i><%=h @exception.file_name %></i> where line <b>#<%=h @exception.line_number %></b> raised:
8
+ <pre><code><%=h @exception.message %></code></pre>
9
+ </p>
10
+
11
+ <p>Extracted source (around line <b>#<%=h @exception.line_number %></b>):
12
+ <pre><code><%=h @exception.source_extract %></code></pre></p>
13
+
14
+ <p><%=h @exception.sub_template_message %></p>
15
+
16
+ <% @real_exception = @exception
17
+ @exception = @exception.original_exception || @exception %>
18
+ <%= render :file => "rescues/_trace.erb" %>
19
+ <% @exception = @real_exception %>
20
+
21
+ <%= render :file => "rescues/_request_and_response.erb" %>
@@ -0,0 +1,2 @@
1
+ <h1>Unknown action</h1>
2
+ <p><%=h @exception.message %></p>
@@ -0,0 +1,3 @@
1
+ module CodeBuddy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ <div class="banner">
2
+ <div class="item"><img src="images/buddy.jpeg" class="buddy"/></div>
3
+ <div class="item"><span class="title">CodeBuddy</span><br/>a friendly place to see your code</div>
4
+ <div class="link"><a href="http://github.com/patshaughnessy/code_buddy">about</a></div>
5
+ <div class="link"><a href="new">paste stack</a></div>
6
+ </div>
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <%= erb :header %>
3
+ <body>
4
+ <%= erb :banner %>
5
+ <div class="form">
6
+ Paste your stack:
7
+ <form action="/" method="post">
8
+ <textarea name="stack" rows="40" cols="130" class="stack_form"></textarea><br/>
9
+ <input type="button" value="submit"/>
10
+ </form>
11
+ </div>
12
+ </body>
13
+ </html>
@@ -0,0 +1,8 @@
1
+ <head>
2
+ <title>Code Buddy</title>
3
+ <link href="stylesheets/code_buddy.css" media="screen" rel="stylesheet" type="text/css" />
4
+ <link href="stylesheets/coderay.css" media="screen" rel="stylesheet" type="text/css" />
5
+ <script src="javascripts/jquery.js" type="text/javascript"></script>
6
+ <script src="javascripts/underscore.js" type="text/javascript"></script>
7
+ <script src="javascripts/backbone.js" type="text/javascript"></script>
8
+ </head>