gui_debugger 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 611c5761370d9850d84dab8563052b0af7cc4cce
4
- data.tar.gz: fbd9002d5af6754b5d761bfdb5457961b9c0200a
3
+ metadata.gz: 1404ed38708bb8b69b6fccfda9ba71695e1fd0ad
4
+ data.tar.gz: 44db585140be44efccd0459f0f8cb67cb517d993
5
5
  SHA512:
6
- metadata.gz: 749dab74c03850a5d3c35c677648be4d14023b25ccc8cea7624bdabc2791be817ae6a2465216e9568b0c25ce56167d7cfc61785a2944e787d44756d46a743d59
7
- data.tar.gz: 68fbd40a0fe0ace4f4e710b65e4f93835317d1a599282d75e3c409cbc2b122629ac2175beb3403b05bff076f13658621049b1b057e67e8fe51bf6df17d3e2c14
6
+ metadata.gz: 5ec677177351b16e00ecf65f27133fd2693985aa212a6dca28e9b89f2b15a6c7ada941695d8f54272b23f97a233c3149caab70484e251688388dc88df5164c01
7
+ data.tar.gz: 37ed4ba4cdcac07bbfdd2026d4777395e609c5dbe69a568796955015e8eea311b2d7eba40b1ebf9f17b07ec16c16a147b5950b7de71a796c71919c8dcf2ac2d7
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.swp
data/gui_debugger.gemspec CHANGED
@@ -1,23 +1,29 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'gui_debugger/version'
5
6
 
6
- Gem::Specification.new do |spec|
7
- spec.name = "gui_debugger"
8
- spec.version = GuiDebugger::VERSION
9
- spec.authors = ["NorimasaAndo"]
10
- spec.email = ["norimasa.ando@gmail.com"]
11
- spec.description = ""
12
- spec.summary = ""
13
- spec.homepage = "https://github.com/yurup/gui_debugger"
14
- spec.license = "MIT"
7
+ Gem::Specification.new do |s|
8
+ s.name = "gui_debugger"
9
+ s.version = GuiDebugger::VERSION
10
+ s.authors = ["NorimasaAndo"]
11
+ s.email = ["norimasa.ando@gmail.com"]
12
+ s.description = ""
13
+ s.summary = ""
14
+ s.homepage = "https://github.com/yurup/gui_debugger"
15
+ s.license = "MIT"
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
22
+ s.add_development_dependency "bundler", "~> 1.3"
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "rspec", "~> 2.9"
25
+ s.add_development_dependency "pry"
26
+ s.add_development_dependency "actionpack", "~> 4.0"
27
+ s.add_development_dependency "binding_of_caller"
28
+ s.add_development_dependency "erubis"
23
29
  end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ module GuiDebugger
4
+ class DebugContext
5
+
6
+ def initialize(context, callers)
7
+ @context = context
8
+ @callers = callers
9
+ end
10
+
11
+ def source(index)
12
+ File.readlines(@callers[index.to_i].eval("__FILE__"))
13
+ end
14
+
15
+ def line_no(index)
16
+ @callers[index.to_i].eval("__LINE__")
17
+ end
18
+
19
+ def disp_source(index, range = 10)
20
+ target_source = source(index)
21
+ target_line_no = line_no(index)
22
+
23
+ min_no = [target_line_no - range, 0].max
24
+ max_no = [target_line_no + range, target_source.count].min
25
+ highlight = (max_no < target_source.count) ? range : target_line_no
26
+
27
+ text = target_source[min_no...max_no].join
28
+
29
+ CodeRay.scan(text, :ruby).div(line_numbers: :inline, line_number_anchors: false, highlight_lines: [highlight])
30
+ end
31
+
32
+ def instance_variables(index)
33
+ vals = @callers[index.to_i].eval("instance_variables")
34
+ arr = vals.select { |val| val.to_s.start_with?("@_") }.sort
35
+ (vals - arr).sort + arr
36
+ end
37
+
38
+ def instance_variable_get(index, val)
39
+ str = @callers[index.to_i].eval("instance_variable_get('#{val}').inspect")
40
+ GuiDebugger.escape str
41
+ end
42
+
43
+ def stack_frame
44
+ @callers.map { |stack| { short_path: short_path(stack) } }
45
+ end
46
+
47
+ def full_path(stack)
48
+ file_path stack
49
+ end
50
+
51
+ def short_path(stack)
52
+ file_path(stack).tap do |path|
53
+ Gem.path.each { |dir_path| path.sub!("#{dir_path}/gems/", "") }
54
+ path.sub!("#{Rails.root.to_s}/", "")
55
+ end
56
+ end
57
+
58
+ def file_path(stack)
59
+ stack.eval("__FILE__")
60
+ end
61
+
62
+ def disp_stack_frame(index)
63
+ disp_source(index)
64
+ end
65
+
66
+ def send_code(index, code)
67
+ return "" if code.blank?
68
+ code = URI.unescape(code)
69
+ @callers[index.to_i].eval(code).to_s
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'erubis'
4
+
5
+ module GuiDebugger
6
+ class DebugPage
7
+ def self.template(template_name)
8
+ File.expand_path("../templates/#{template_name}.html.erb", __FILE__)
9
+ end
10
+
11
+ def self.display
12
+ text = File.read(template("main"))
13
+ html = Erubis::Eruby.new(text).evaluate(context: GuiDebugger.debug_context)
14
+
15
+ [200, { "Content-Type" => "text/html; charset=utf-8" }, [html]]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support'
4
+ require "gui_debugger/debug_context.rb"
5
+
6
+ module GuiDebugger
7
+ module GuiDebug
8
+ extend ActiveSupport::Concern
9
+
10
+ def debug
11
+ GuiDebugger.debug_context = DebugContext.new(binding, binding.callers)
12
+ throw :gui_debugger
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module GuiDebugger
4
+ class Middleware
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ if %r{\A/__gui_debugger/(?<method>\w+)(/(?<index>\d+))?(/(?<val>.+))?} =~ env["PATH_INFO"]
12
+ data = GuiDebugger.debug_context.send(method, *[index, val].compact)
13
+ [200, { "Content-Type" => "text/plain; charset=utf-8" }, [JSON.dump({ data: data })]]
14
+ else
15
+ catch(:gui_debugger) do
16
+ return @app.call(env)
17
+ end
18
+
19
+ DebugPage::display
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module GuiDebugger
4
+ class Railtie < Rails::Railtie
5
+ initializer "gui_debugger.configuration" do
6
+ if development?
7
+ Binding.send(:include, GuiDebugger::GuiDebug)
8
+ Rails.application.middleware.use GuiDebugger::Middleware
9
+ end
10
+ end
11
+
12
+ def development?
13
+ !Rails.env.production?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,156 @@
1
+ <!DOCTYPE html>
2
+ <html ng-app="debugApp">
3
+ <head>
4
+ <title>DebugPage</title>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
8
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
9
+ <style>
10
+ .contents {
11
+ padding: 80px 0 0 0;
12
+ }
13
+ .non-active {
14
+ display: none;
15
+ }
16
+ .stack_frame {
17
+ height: 250px;
18
+ overflow: auto;
19
+ }
20
+ .eval {
21
+ max-width: 850px;
22
+ margin-bottom: 20px;
23
+ }
24
+ .source {
25
+ height: 350px;
26
+ overflow: auto;
27
+ margin-bottom: 10px;
28
+ }
29
+ .variables {
30
+ height: 400px;
31
+ overflow: auto;
32
+ line-height: 10px;
33
+ }
34
+ .variables ul li {
35
+ list-style: none;
36
+ }
37
+ .result {
38
+ height: 250px;
39
+ overflow: auto;
40
+ }
41
+ </style>
42
+ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
43
+ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular-resource.min.js"></script>
44
+ </head>
45
+ <body ng-controller="DebugCtrl">
46
+
47
+ <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
48
+ <div class="container">
49
+ <div class="navbar-header">
50
+ <a class="navbar-brand" href="#">Debug page</a>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <div class="container">
56
+ <div class="contents">
57
+ <div class="row">
58
+ <div class="eval col-md-7">
59
+ <div class="source" ng-bind-html="source" ng-init="disp_stack_frame('1')"></div>
60
+ <form ng-submit="send_code()">
61
+ <input type="text" ng-model="code" size="80" placeholder="enter code here...">
62
+ <input class="btn-primary" type="submit" value="send">
63
+ </form>
64
+ </div>
65
+ <pre class="variables col-md-offset-7">
66
+ <ul>
67
+ <li style="margin-left:-110px; margin-top:-5px;" ng-repeat="val in vals">
68
+ <a href="" ng-click="instance_variable_get(val)" ng-bind="val"></a>
69
+ </li>
70
+ </ul>
71
+ </pre>
72
+ </div>
73
+
74
+ <div class="clearfix"></div>
75
+
76
+ <div class="row">
77
+ <div class="col-md-7 result">
78
+ <pre ng-bind-html="disp" style="white-space: pre;"></pre>
79
+ </div>
80
+
81
+ <div class="list-group col-md-offset-7 stack_frame">
82
+ <% @context.stack_frame.each_with_index do |stack, index| %>
83
+ <% next if index == 0 %>
84
+ <a href="" class="list-group-item" ng-class='{"active":selected_index == <%= index %>}' ng-click="disp_stack_frame('<%= index %>')">
85
+ <%= stack[:short_path] %>
86
+ </a>
87
+ <% end %>
88
+ </div>
89
+ </div>
90
+
91
+ </div><!-- /.contents -->
92
+ </div><!-- /.container -->
93
+
94
+ <script>
95
+ var debugApp = angular.module('debugApp', ['ngResource']);
96
+
97
+ debugApp.factory('InstanceVal', ['$resource', function($resource) {
98
+ return $resource('/__gui_debugger/instance_variable_get/:index/:val', {}, {
99
+ query: { method: 'GET', isArray: false }
100
+ });
101
+ }]);
102
+
103
+ debugApp.factory('InstanceValList', ['$resource', function($resource) {
104
+ return $resource('/__gui_debugger/instance_variables/:index', {}, {
105
+ query: { method: 'GET', isArray: false }
106
+ });
107
+ }]);
108
+
109
+ debugApp.factory('DispStackFrame', ['$resource', function($resource) {
110
+ return $resource('/__gui_debugger/disp_stack_frame/:index', {}, {
111
+ query: { method: 'GET', isArray: false }
112
+ });
113
+ }]);
114
+
115
+ debugApp.factory('SendCode', ['$resource', function($resource) {
116
+ return $resource('/__gui_debugger/send_code/:index/:code', {}, {
117
+ query: { method: 'GET', isArray: false }
118
+ });
119
+ }]);
120
+
121
+ debugApp.controller('DebugCtrl', ['$scope', 'InstanceVal', 'InstanceValList', 'DispStackFrame', 'SendCode', '$sce',
122
+ function($scope, InstanceVal, InstanceValList, DispStackFrame, SendCode, $sce) {
123
+ $scope.instance_variable_get = function(val) {
124
+ InstanceVal.query({ index: $scope.selected_index, val: val }, function(res) {
125
+ $scope.disp = $sce.trustAsHtml(res.data);
126
+ });
127
+ };
128
+
129
+ $scope.disp_stack_frame = function(index) {
130
+ DispStackFrame.query({ index: index }, function(res) {
131
+ $scope.source = $sce.trustAsHtml(res.data);
132
+ });
133
+ $scope.selected_index = index;
134
+ $scope.instance_variables(index)
135
+ };
136
+
137
+ $scope.instance_variables = function(index) {
138
+ InstanceValList.query({ index: index }, function(res) {
139
+ $scope.vals = res.data;
140
+ });
141
+ };
142
+
143
+ $scope.send_code = function() {
144
+ SendCode.query({ index: $scope.selected_index, code: $scope.code }, function(res) {
145
+ $scope.disp = $sce.trustAsHtml(res.data);
146
+ });
147
+ };
148
+
149
+ $scope.selected_index = 1;
150
+ }]);
151
+ </script>
152
+
153
+ <script src="https://code.jquery.com/jquery.js"></script>
154
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
155
+ </body>
156
+ </html>
@@ -1,3 +1,3 @@
1
1
  module GuiDebugger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gui_debugger.rb CHANGED
@@ -1,5 +1,19 @@
1
1
  require "gui_debugger/version"
2
+ require "gui_debugger/gui_debug"
3
+ require "gui_debugger/debug_page"
4
+ require "gui_debugger/middleware"
2
5
 
3
6
  module GuiDebugger
4
- # Your code goes here...
7
+
8
+ class << self
9
+ # retain only one context for debug when guidebug
10
+ # method is called.
11
+ attr_accessor :debug_context
12
+ end
13
+
14
+ def self.escape(str)
15
+ ERB::Util.h(str.gsub('\n', "\n"))
16
+ end
5
17
  end
18
+
19
+ require 'gui_debugger/railtie' if defined?(Rails)
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+ require "pry"
3
+
4
+ describe GuiDebugger do
5
+ it "pending..." do
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << File.expand_path("../lib", __FILE__)
2
+ require "gui_debugger"
metadata CHANGED
@@ -1,41 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gui_debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - NorimasaAndo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: binding_of_caller
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: erubis
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
39
109
  - !ruby/object:Gem::Version
40
110
  version: '0'
41
111
  description: ''
@@ -45,14 +115,22 @@ executables: []
45
115
  extensions: []
46
116
  extra_rdoc_files: []
47
117
  files:
48
- - .gitignore
118
+ - ".gitignore"
49
119
  - Gemfile
50
120
  - LICENSE.txt
51
121
  - README.md
52
122
  - Rakefile
53
123
  - gui_debugger.gemspec
54
124
  - lib/gui_debugger.rb
125
+ - lib/gui_debugger/debug_context.rb
126
+ - lib/gui_debugger/debug_page.rb
127
+ - lib/gui_debugger/gui_debug.rb
128
+ - lib/gui_debugger/middleware.rb
129
+ - lib/gui_debugger/railtie.rb
130
+ - lib/gui_debugger/templates/main.html.erb
55
131
  - lib/gui_debugger/version.rb
132
+ - spec/gui_debugger_spec.rb
133
+ - spec/spec_helper.rb
56
134
  homepage: https://github.com/yurup/gui_debugger
57
135
  licenses:
58
136
  - MIT
@@ -63,19 +141,20 @@ require_paths:
63
141
  - lib
64
142
  required_ruby_version: !ruby/object:Gem::Requirement
65
143
  requirements:
66
- - - '>='
144
+ - - ">="
67
145
  - !ruby/object:Gem::Version
68
146
  version: '0'
69
147
  required_rubygems_version: !ruby/object:Gem::Requirement
70
148
  requirements:
71
- - - '>='
149
+ - - ">="
72
150
  - !ruby/object:Gem::Version
73
151
  version: '0'
74
152
  requirements: []
75
153
  rubyforge_project:
76
- rubygems_version: 2.0.3
154
+ rubygems_version: 2.2.0
77
155
  signing_key:
78
156
  specification_version: 4
79
157
  summary: ''
80
- test_files: []
81
- has_rdoc:
158
+ test_files:
159
+ - spec/gui_debugger_spec.rb
160
+ - spec/spec_helper.rb