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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code_buddy (0.0.5)
4
+ code_buddy (0.0.6)
5
5
  coderay (~> 0.9.6)
6
6
  json_pure (~> 1.4.6)
7
7
  rack
@@ -4,12 +4,11 @@ module CodeBuddy
4
4
  set :public, File.dirname(__FILE__) + '/public'
5
5
 
6
6
  class << self
7
- attr_reader :stack
8
- attr_reader :rails
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)
@@ -5,7 +5,7 @@ module CodeBuddy
5
5
  end
6
6
 
7
7
  def call(env)
8
- if env['PATH_INFO'] =~ /^\/code_buddy(.*)/
8
+ if env['PATH_INFO'] =~ /^\/code_buddy(.*)/ && Rails.env.development?
9
9
  env['PATH_INFO'] = $1
10
10
  App.new.call(env)
11
11
  else
@@ -1,130 +1,129 @@
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 })
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
- // 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
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
- 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);
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
+ })
@@ -104,3 +104,8 @@ li {
104
104
  line-height: 23px;
105
105
  list-style: none;
106
106
  }
107
+
108
+ li:hover {
109
+ background:#444;
110
+ cursor:pointer;
111
+ }
@@ -1,3 +1,3 @@
1
1
  module CodeBuddy
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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/>a friendly place to see your code</div>
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>Code Buddy</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
- def rails_version
12
- Rails::VERSION::MAJOR
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
@@ -5,6 +5,16 @@ require 'mocha'
5
5
  require 'sinatra'
6
6
 
7
7
  module Rails
8
+ class MockEnvironment
9
+ def development?
10
+ true
11
+ end
12
+ end
13
+ class << self
14
+ def env
15
+ MockEnvironment.new
16
+ end
17
+ end
8
18
  class Railtie
9
19
  def self.initializer(name); end
10
20
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
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-11 00:00:00 -05:00
17
+ date: 2010-12-13 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency