code_buddy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,25 @@
1
+ <%= erb :header %>
2
+ <html>
3
+ <body>
4
+ <%= erb :banner %>
5
+ <br/>
6
+ <div id="legend">
7
+ commands:<br/>
8
+ &#8593; move up the stack<br/>
9
+ &#8595; move down the stack<br/>
10
+ click to select a stack frame<br/>
11
+ </div>
12
+ </div>
13
+ <ul id="stack"></ul>
14
+ <div id='code'></div>
15
+ <script src="javascripts/code_buddy.js" type="text/javascript"></script>
16
+ <script>
17
+ var stack = new Stack(<%= @stack.to_json %>);
18
+ var stackView = new StackView({model: stack});
19
+ stackView.render();
20
+ $(document).keydown(function(event) {
21
+ return stack.view.changeSelectionOnArrow(event)
22
+ })
23
+ </script>
24
+ </body>
25
+ </html>
@@ -0,0 +1,53 @@
1
+ <html>
2
+ <head>
3
+ <title>Code Buddy</title>
4
+ <link href="stylesheets/code_buddy.css" media="screen" rel="stylesheet" type="text/css" />
5
+ <link href="stylesheets/coderay.css" media="screen" rel="stylesheet" type="text/css" />
6
+ <script src="javascripts/jquery.js" type="text/javascript"></script>
7
+ <script src="javascripts/underscore.js" type="text/javascript"></script>
8
+ <script src="javascripts/backbone.js" type="text/javascript"></script>
9
+ </head>
10
+ <body>
11
+ <img src="images/buddy.jpeg"/>
12
+ <div class="banner">
13
+ <h1>CodeBuddy</h1>
14
+ <h2>a friendly place to see your code</h2>
15
+ </div>
16
+
17
+ <div class="legend">
18
+ <div>&#8593; move up the stack</div>
19
+ <div>&#8595; move down the stack</div>
20
+ </div>
21
+
22
+ </div>
23
+
24
+ <div class="code_buddy">
25
+ <ul id="stack"></ul>
26
+ <div id='code'></div>
27
+ </div>
28
+
29
+ <script src="javascripts/code_buddy.js" type="text/javascript"></script>
30
+ <script>
31
+
32
+ var stack = new Stack(<%= @stack.to_json %>);
33
+
34
+ var stackView = new StackView({model: stack});
35
+ stackView.render();
36
+
37
+ // Why don't backbone events work???
38
+ $(document).keydown(function(event) {
39
+ var ret = stack.view.changeSelectionOnArrow(event)
40
+ var offset = $(stack.selectedAddress().view.el).offset().top
41
+ var windowHeight = $(window).height()
42
+ if (offset > windowHeight + $(window).scrollTop()) {
43
+ $('html,body').animate({scrollTop: offset - 200}, 500);
44
+ } else if (offset < $(window).scrollTop()) {
45
+ $('html,body').animate({scrollTop: offset - 500}, 500);
46
+ }
47
+ return ret;
48
+ })
49
+
50
+
51
+ </script>
52
+ </body>
53
+ </html>
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CodeBuddy::App do
4
+ it 'should have specs'
5
+
6
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CodeBuddy::ShowExceptions do
4
+ subject { CodeBuddy::ShowExceptions.new }
5
+
6
+ describe 'Non code_buddy URLs' do
7
+ it 'should not call the Sinatra app when a non code_buddy URL is found' do
8
+ CodeBuddy::App.expects(:new).never
9
+ env = { 'PATH_INFO' => '/some_other_path' }
10
+ subject.call(env)
11
+ end
12
+
13
+ it 'should not call the Sinatra app when code_buddy is found later in the URL' do
14
+ CodeBuddy::App.expects(:new).never
15
+ env = { 'PATH_INFO' => '/some_other_path/code_buddy' }
16
+ subject.call(env)
17
+ end
18
+ end
19
+
20
+ describe 'code_buddy URLs' do
21
+ it 'should call the Sinatra app when a code_buddy URL is found and pass in the remaining path only' do
22
+ app = mock
23
+ CodeBuddy::App.expects(:new).returns(app)
24
+ app.expects(:call).with({ 'PATH_INFO' => '/12' })
25
+ env = { 'PATH_INFO' => '/code_buddy/12' }
26
+ subject.call(env)
27
+ end
28
+
29
+ it 'should call the Sinatra app when a code_buddy URL is found and pass in the remaining path only' do
30
+ app = mock
31
+ CodeBuddy::App.expects(:new).returns(app)
32
+ app.expects(:call).with({ 'PATH_INFO' => '' })
33
+ env = { 'PATH_INFO' => '/code_buddy' }
34
+ subject.call(env)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'mocha'
5
+ require 'sinatra'
6
+
7
+ module Rails
8
+ class Railtie
9
+ def self.initializer(name); end
10
+ end
11
+ end
12
+ module ActionDispatch
13
+ class ShowExceptions
14
+ def call(env); end
15
+ end
16
+ end
17
+
18
+ require 'code_buddy'
19
+
20
+ # Requires supporting ruby files with custom matchers and macros, etc,
21
+ # in spec/support/ and its subdirectories.
22
+ Dir[File.join(File.dirname(__FILE__), "spec/support/**/*.rb")].each {|f| require f}
23
+
24
+ RSpec.configure do |config|
25
+ config.mock_with :mocha
26
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CodeBuddy::StackFrame do
4
+ subject { CodeBuddy::StackFrame.new("/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:3:in `new'") }
5
+
6
+ describe 'initialization' do
7
+ before do
8
+ CodeBuddy::StackFrame.any_instance.expects(:code).returns('def some_code_here end')
9
+ end
10
+
11
+ it 'should have the file path' do
12
+ subject.path.should == '/gems/actionpack-3.0.3/lib/abstract_controller/base.rb'
13
+ end
14
+ it 'should have the line number' do
15
+ subject.line.should == 3
16
+ end
17
+ end
18
+
19
+ describe 'formatting code from the source file' do
20
+ describe 'with a valid file' do
21
+ let(:source_code) { [
22
+ "require 'active_support/configurable'\n",
23
+ "require 'active_support/descendants_tracker'\n",
24
+ "require 'active_support/core_ext/module/anonymous'\n",
25
+ "\n",
26
+ "module AbstractController\n",
27
+ " class Error < StandardError; end\n",
28
+ " class ActionNotFound < StandardError; end\n",
29
+ "\n",
30
+ " # <tt>AbstractController::Base</tt> is a low-level API. Nobody should be\n",
31
+ " # using it directly, and subclasses (like ActionController::Base) are\n",
32
+ " # expected to provide their own +render+ method, since rendering means\n",
33
+ " # different things depending on the context. \n",
34
+ " class Base\n",
35
+ " attr_internal :response_body\n",
36
+ " attr_internal :action_name\n",
37
+ " attr_internal :formats\n",
38
+ "\n",
39
+ " include ActiveSupport::Configurable\n",
40
+ " extend ActiveSupport::DescendantsTracker\n",
41
+ "\n",
42
+ " class << self\n",
43
+ " attr_reader :abstract\n",
44
+ " alias_method :abstract?, :abstract\n",
45
+ "\n",
46
+ " # Define a controller as abstract. See internal_methods for more\n",
47
+ " # details.\n",
48
+ " def abstract!\n",
49
+ " @abstract = true\n",
50
+ " end\n",
51
+ "\n",
52
+ " # A list of all internal methods for a controller. This finds the first\n",
53
+ " # abstract superclass of a controller, and gets a list of all public\n",
54
+ " # instance methods on that abstract class. Public instance methods of\n"
55
+ ] }
56
+
57
+ before do
58
+ File.expects(:new).with('/gems/actionpack-3.0.3/lib/abstract_controller/base.rb').
59
+ returns(mock(:readlines=>source_code))
60
+ end
61
+
62
+ it 'should read code from the middle of a file' do
63
+ CodeRay.expects(:scan).with(source_code[4..25], :ruby).returns(parsed_code=mock)
64
+ parsed_code.expects(:html).
65
+ with(:line_number_start => 5, :line_numbers => :inline, :wrap => :span, :bold_every=>false).
66
+ returns(formatted_source=mock)
67
+
68
+ formatted_source.expects(:split).with("\n").returns((5..25).to_a)
69
+
70
+ stack_frame = CodeBuddy::StackFrame.new("/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:15:in `new'")
71
+ stack_frame.code.should == "5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n<span class='container selected'>15<span class='overlay'></span></span>\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25"
72
+ end
73
+ it 'should read code from the top of a file' do
74
+ CodeRay.expects(:scan).with(source_code[0..13], :ruby).returns(parsed_code=mock)
75
+ parsed_code.expects(:html).
76
+ with(:line_number_start => 1, :line_numbers => :inline, :wrap => :span, :bold_every=>false).
77
+ returns(formatted_source=mock)
78
+ formatted_source.expects(:split).with("\n").returns((1..13).to_a)
79
+
80
+ stack_frame = CodeBuddy::StackFrame.new("/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:3:in `new'")
81
+
82
+ stack_frame.code.should == "1\n2\n<span class='container selected'>3<span class='overlay'></span></span>\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13"
83
+ end
84
+ it 'should read code from the bottom of a file' do
85
+ CodeRay.expects(:scan).with(source_code[19..32], :ruby).returns(parsed_code=mock)
86
+ parsed_code.expects(:html).
87
+ with(:line_number_start => 20, :line_numbers => :inline, :wrap => :span, :bold_every=>false).
88
+ returns(formatted_source=mock)
89
+ formatted_source.expects(:split).with("\n").returns((20..33).to_a)
90
+
91
+ stack_frame = CodeBuddy::StackFrame.new("/gems/actionpack-3.0.3/lib/abstract_controller/base.rb:30:in `new'")
92
+
93
+ stack_frame.code.should == "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n<span class='container selected'>30<span class='overlay'></span></span>\n31\n32\n33"
94
+ end
95
+ end
96
+
97
+ it 'should return an error message in the code when unable to read the source file' do
98
+ File.expects(:new).with('/no/such/file.rb').
99
+ raises(Errno::ENOENT.new('/no/such/file.rb'))
100
+
101
+ stack_frame = CodeBuddy::StackFrame.new('/no/such/file.rb')
102
+ stack_frame.code.should == "<span class=\"coderay\">Unable to read file:\n&nbsp;\"/no/such/file.rb\"</span>"
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CodeBuddy::Stack do
4
+
5
+ it 'should create a series of stack frames from an exception' do
6
+ backtrace = [
7
+ "/Users/me/my_app/config.ru:1:in `new'",
8
+ "/Users/me/my_app/config.ru:1"
9
+ ]
10
+ CodeBuddy::StackFrame.expects(:new).with("/Users/me/my_app/config.ru:1:in `new'").returns(frame1=mock)
11
+ CodeBuddy::StackFrame.expects(:new).with("/Users/me/my_app/config.ru:1" ).returns(frame2=mock)
12
+ mock_exception = mock(:backtrace=>backtrace)
13
+ mock_exception.expects(:is_a?).with(Exception).returns(true)
14
+ stack = CodeBuddy::Stack.new mock_exception
15
+ stack.stack_frames.should == [frame1, frame2]
16
+ end
17
+
18
+ it 'should save the currently selected stack frame' do
19
+ mock_exception = mock(:backtrace=>'')
20
+ mock_exception.expects(:is_a?).with(Exception).returns(true)
21
+ stack = CodeBuddy::Stack.new mock_exception
22
+ stack.selected = 3
23
+ stack.selected.should == 3
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: code_buddy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Pat Shaughnessy, Alex Rothenberg, Daniel Higginbotham
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 0
31
+ version: 1.2.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: sinatra
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ - 0
45
+ version: 1.1.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json_pure
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 4
58
+ - 6
59
+ version: 1.4.6
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: coderay
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 9
72
+ - 6
73
+ version: 0.9.6
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: rake
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 8
86
+ - 7
87
+ version: 0.8.7
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: rspec
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 2
99
+ - 2
100
+ - 0
101
+ version: 2.2.0
102
+ type: :development
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: mocha
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ - 9
114
+ - 10
115
+ version: 0.9.10
116
+ type: :development
117
+ version_requirements: *id007
118
+ description: See the Ruby code running in your app.
119
+ email:
120
+ - pat@patshaughnessy.net, alex@alexrothenberg.com, daniel@flyingmachinestudios.com
121
+ executables:
122
+ - code_buddy
123
+ extensions: []
124
+
125
+ extra_rdoc_files: []
126
+
127
+ files:
128
+ - .gitignore
129
+ - .rvmrc
130
+ - Gemfile
131
+ - Gemfile.lock
132
+ - LICENSE
133
+ - README.rdoc
134
+ - Rakefile
135
+ - bin/code_buddy
136
+ - code_buddy.gemspec
137
+ - lib/code_buddy.rb
138
+ - lib/code_buddy/app.rb
139
+ - lib/code_buddy/middleware.rb
140
+ - lib/code_buddy/public/images/buddy.jpeg
141
+ - lib/code_buddy/public/javascripts/backbone.js
142
+ - lib/code_buddy/public/javascripts/code_buddy.js
143
+ - lib/code_buddy/public/javascripts/jquery.js
144
+ - lib/code_buddy/public/javascripts/underscore.js
145
+ - lib/code_buddy/public/stylesheets/code_buddy.css
146
+ - lib/code_buddy/public/stylesheets/coderay.css
147
+ - lib/code_buddy/stack.rb
148
+ - lib/code_buddy/stack_frame.rb
149
+ - lib/code_buddy/templates/rescues/_request_and_response.erb
150
+ - lib/code_buddy/templates/rescues/_trace.erb
151
+ - lib/code_buddy/templates/rescues/diagnostics.erb
152
+ - lib/code_buddy/templates/rescues/layout.erb
153
+ - lib/code_buddy/templates/rescues/missing_template.erb
154
+ - lib/code_buddy/templates/rescues/routing_error.erb
155
+ - lib/code_buddy/templates/rescues/template_error.erb
156
+ - lib/code_buddy/templates/rescues/unknown_action.erb
157
+ - lib/code_buddy/version.rb
158
+ - lib/code_buddy/views/banner.erb
159
+ - lib/code_buddy/views/form.erb
160
+ - lib/code_buddy/views/header.erb
161
+ - lib/code_buddy/views/index.erb
162
+ - lib/code_buddy/views/orig.erb
163
+ - spec/app_spec.rb
164
+ - spec/middleware_spec.rb
165
+ - spec/spec_helper.rb
166
+ - spec/stack_frame_spec.rb
167
+ - spec/stack_spec.rb
168
+ has_rdoc: true
169
+ homepage: http://github.com/patshaughnessy/code_buddy
170
+ licenses: []
171
+
172
+ post_install_message:
173
+ rdoc_options: []
174
+
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ segments:
189
+ - 0
190
+ version: "0"
191
+ requirements: []
192
+
193
+ rubyforge_project: code_buddy
194
+ rubygems_version: 1.3.6
195
+ signing_key:
196
+ specification_version: 3
197
+ summary: See the Ruby code running in your app.
198
+ test_files:
199
+ - spec/app_spec.rb
200
+ - spec/middleware_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/stack_frame_spec.rb
203
+ - spec/stack_spec.rb