code_buddy 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/code_buddy/app.rb +2 -3
- data/lib/code_buddy/middleware.rb +1 -1
- data/lib/code_buddy/public/javascripts/code_buddy.js +125 -126
- data/lib/code_buddy/public/stylesheets/code_buddy.css +5 -0
- data/lib/code_buddy/version.rb +1 -1
- data/lib/code_buddy/views/banner.erb +1 -1
- data/lib/code_buddy/views/header.erb +1 -1
- data/lib/code_buddy.rb +10 -9
- data/spec/spec_helper.rb +10 -0
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/lib/code_buddy/app.rb
CHANGED
@@ -4,12 +4,11 @@ module CodeBuddy
|
|
4
4
|
set :public, File.dirname(__FILE__) + '/public'
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_reader
|
8
|
-
|
7
|
+
attr_reader :stack
|
8
|
+
attr_accessor :rails
|
9
9
|
|
10
10
|
def exception=(exception)
|
11
11
|
@stack = Stack.new(exception)
|
12
|
-
@rails = true
|
13
12
|
end
|
14
13
|
|
15
14
|
def stack_string=(stack_string)
|
@@ -1,130 +1,129 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
},
|
22
|
-
|
23
|
-
addresses: function() {
|
24
|
-
return this.get('addresses')
|
25
|
-
},
|
26
|
-
|
27
|
-
selectedAddress: function() {
|
28
|
-
var selected = this.get('selected')
|
29
|
-
return this.addresses().at(selected)
|
30
|
-
},
|
31
|
-
|
32
|
-
selectionChanged: function(x) {
|
33
|
-
this.updateSelectedAddress(x)
|
34
|
-
this.view.render()
|
35
|
-
},
|
36
|
-
|
37
|
-
updateSelectedAddress: function(x) {
|
38
|
-
this.addresses().at(x.previousAttributes().selected).view.render()
|
39
|
-
this.addresses().at(x.changedAttributes().selected).view.render()
|
1
|
+
var Address = Backbone.Model.extend({
|
2
|
+
selected: function() {
|
3
|
+
return stack.selectedAddress() == this
|
4
|
+
},
|
5
|
+
});
|
6
|
+
|
7
|
+
var Addresses = Backbone.Collection.extend({model:Address})
|
8
|
+
|
9
|
+
var Stack = Backbone.Model.extend({
|
10
|
+
initialize: function() {
|
11
|
+
this.bind('change:selected', this.selectionChanged);
|
12
|
+
this.set({
|
13
|
+
addresses: new Addresses(this.get('stack_frames'))
|
14
|
+
})
|
15
|
+
},
|
16
|
+
|
17
|
+
setSelection: function(newSelected) {
|
18
|
+
if (newSelected >= 0 && newSelected < this.addresses().size()) {
|
19
|
+
this.set({ selected: newSelected })
|
40
20
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
21
|
+
},
|
22
|
+
|
23
|
+
addresses: function() {
|
24
|
+
return this.get('addresses')
|
25
|
+
},
|
26
|
+
|
27
|
+
selectedAddress: function() {
|
28
|
+
var selected = this.get('selected')
|
29
|
+
return this.addresses().at(selected)
|
30
|
+
},
|
31
|
+
|
32
|
+
selectionChanged: function(x) {
|
33
|
+
this.updateSelectedAddress(x)
|
34
|
+
this.view.render()
|
35
|
+
},
|
36
|
+
|
37
|
+
updateSelectedAddress: function(x) {
|
38
|
+
this.addresses().at(x.previousAttributes().selected).view.render()
|
39
|
+
this.addresses().at(x.changedAttributes().selected).view.render()
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
// ADDRESS VIEW - SELECTED ADDRESS IN BOLD
|
46
|
+
var AddressView = Backbone.View.extend({
|
47
|
+
tagName: "li",
|
48
|
+
|
49
|
+
template: _.template("<span class='container'><%= path %>:<%= line%><span class='overlay'></span></span>"),
|
50
|
+
|
51
|
+
initialize: function() {
|
52
|
+
_.bindAll(this, 'render', 'close');
|
53
|
+
this.model.bind('change', this.render);
|
54
|
+
this.model.view = this;
|
55
|
+
},
|
56
|
+
|
57
|
+
events: {
|
58
|
+
click: "open"
|
59
|
+
},
|
60
|
+
open: function() {
|
61
|
+
stack.set({selected: this.model.cid.substr(1)-1});
|
62
|
+
},
|
63
|
+
|
64
|
+
render: function() {
|
65
|
+
var html = this.template(this.model.toJSON())
|
66
|
+
|
67
|
+
$(this.el).html(html);
|
68
|
+
if (this.model.selected()) {
|
69
|
+
$(this.el).addClass('selected')
|
70
|
+
} else {
|
71
|
+
$(this.el).removeClass('selected')
|
72
|
+
}
|
73
|
+
return this;
|
74
|
+
}
|
75
|
+
})
|
76
|
+
|
77
|
+
// STACK VIEW - LOGIC FOR ASSIGNING EACH ADDRESS VIEW TO EACH LI TAG
|
78
|
+
var StackView = Backbone.View.extend({
|
79
|
+
|
80
|
+
el: $("#stack"),
|
81
|
+
|
82
|
+
events: {
|
83
|
+
"keypress #stack" : "changeSelectionOnArrow"
|
84
|
+
},
|
85
|
+
|
86
|
+
initialize: function() {
|
87
|
+
_.bindAll(this, 'render', 'close');
|
88
|
+
this.model.bind('change', this.render);
|
89
|
+
this.model.view = this;
|
90
|
+
|
91
|
+
this.model.get('addresses').each(this.addOneAddress);
|
92
|
+
},
|
93
|
+
|
94
|
+
changeSelectionOnArrow: function(event) {
|
95
|
+
var origSelection = this.model.get('selected')
|
96
|
+
var newSelection = origSelection
|
97
|
+
if (event.keyCode == 38) {
|
98
|
+
newSelection = origSelection - 1
|
99
|
+
} else if (event.keyCode == 40) {
|
100
|
+
newSelection = origSelection + 1
|
101
|
+
}
|
102
|
+
if (newSelection != origSelection) {
|
103
|
+
this.model.setSelection(newSelection)
|
104
|
+
|
105
|
+
var offset = $(stack.selectedAddress().view.el).offset()
|
106
|
+
var windowHeight = $(window).height()
|
107
|
+
if (offset.top > windowHeight + $(window).scrollTop() - 10) {
|
108
|
+
// scroll down
|
109
|
+
$('html,body').animate({scrollTop: offset.top - 200}, 500);
|
110
|
+
} else if (offset.top < $(window).scrollTop() + 100) {
|
111
|
+
// scroll up
|
112
|
+
$('html,body').animate({scrollTop: offset.top - 500}, 500);
|
101
113
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
var offset = $(stack.selectedAddress().view.el).offset()
|
106
|
-
var windowHeight = $(window).height()
|
107
|
-
if (offset.top > windowHeight + $(window).scrollTop() - 10) {
|
108
|
-
// scroll down
|
109
|
-
$('html,body').animate({scrollTop: offset.top - 200}, 500);
|
110
|
-
} else if (offset.top < $(window).scrollTop() + 100) {
|
111
|
-
// scroll up
|
112
|
-
$('html,body').animate({scrollTop: offset.top - 500}, 500);
|
113
|
-
}
|
114
|
-
return false
|
115
|
-
} else {
|
116
|
-
return true
|
117
|
-
}
|
118
|
-
},
|
119
|
-
|
120
|
-
addOneAddress: function(address, index) {
|
121
|
-
var view = new AddressView({model: address});
|
122
|
-
this.$("#stack").append(view.render().el);
|
123
|
-
},
|
124
|
-
|
125
|
-
render: function() {
|
126
|
-
$('#code').html(this.model.selectedAddress().get('code'))
|
114
|
+
return false
|
115
|
+
} else {
|
116
|
+
return true
|
127
117
|
}
|
128
|
-
|
129
|
-
|
118
|
+
},
|
119
|
+
|
120
|
+
addOneAddress: function(address, index) {
|
121
|
+
var view = new AddressView({model: address});
|
122
|
+
this.$("#stack").append(view.render().el);
|
123
|
+
},
|
124
|
+
|
125
|
+
render: function() {
|
126
|
+
$('#code').html(this.model.selectedAddress().get('code'))
|
127
|
+
}
|
130
128
|
|
129
|
+
})
|
data/lib/code_buddy/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="banner">
|
2
2
|
<div class="item"><img src="<%= @static_file_prefix %>images/buddy.jpeg" class="buddy"/></div>
|
3
|
-
<div class="item"><span class="title">CodeBuddy</span><br/>
|
3
|
+
<div class="item"><span class="title">CodeBuddy</span><br/>See your Ruby stack come alive</div>
|
4
4
|
<div class="link"><a href="http://github.com/patshaughnessy/code_buddy">about</a></div>
|
5
5
|
<div class="link"><a href="<%= @static_file_prefix %>new">paste stack</a></div>
|
6
6
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<head>
|
2
|
-
<title>
|
2
|
+
<title>CodeBuddy</title>
|
3
3
|
<link href="<%= @static_file_prefix %>stylesheets/code_buddy.css" media="screen" rel="stylesheet" type="text/css" />
|
4
4
|
<link href="<%= @static_file_prefix %>stylesheets/coderay.css" media="screen" rel="stylesheet" type="text/css" />
|
5
5
|
<script src="<%= @static_file_prefix %>javascripts/jquery.js" type="text/javascript"></script>
|
data/lib/code_buddy.rb
CHANGED
@@ -8,15 +8,16 @@ require 'code_buddy/stack'
|
|
8
8
|
require 'code_buddy/stack_frame'
|
9
9
|
require 'code_buddy/middleware'
|
10
10
|
|
11
|
-
|
12
|
-
Rails
|
11
|
+
begin
|
12
|
+
if Rails.env.development?
|
13
|
+
CodeBuddy::App.rails = true
|
14
|
+
case Rails::VERSION::MAJOR
|
15
|
+
when 2:
|
16
|
+
require 'code_buddy/rails2/monkey_patch_action_controller'
|
17
|
+
when 3:
|
18
|
+
require 'code_buddy/rails3/railtie.rb'
|
19
|
+
end
|
20
|
+
end
|
13
21
|
rescue NameError
|
14
22
|
nil
|
15
23
|
end
|
16
|
-
|
17
|
-
case rails_version
|
18
|
-
when 2:
|
19
|
-
require 'code_buddy/rails2/monkey_patch_action_controller'
|
20
|
-
when 3:
|
21
|
-
require 'code_buddy/rails3/railtie.rb'
|
22
|
-
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pat Shaughnessy, Alex Rothenberg, Daniel Higginbotham
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-13 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|