localtower 0.1.9 → 0.2.0

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: c0a94e3d3bd8df7939b70dff9b955d4c00eab463
4
- data.tar.gz: 6d211998789567a6efb5bc3a2c620497ba559876
3
+ metadata.gz: dcfd04482b7b0798e66c863f019e56a6b5af16d2
4
+ data.tar.gz: c8729e1ed2b16a5a09851e3e5ee828d59137cfc7
5
5
  SHA512:
6
- metadata.gz: 8cef1c348104c018a47ce550760d49d527def661b9e8d6de4fd402e58ff2761041965b90244e8c621b8c30359a008ccbcbbabe4efe15ec5ad7ea3f1bb82abe16
7
- data.tar.gz: 8ca6c334cd7b0e5fb8b2da3b5c122b039b82a2199e5c78bd1ca5e7ef6df05a5d8fb36ac067b5c3a68a14241e67b574608034e2bd41d4262020111a4cd8ee91cd
6
+ metadata.gz: 2b5f5ad3608a85599a661ae92cb2da043039f7b45a49e2943aafea4b2ae6426bd2edc9dfc037e9dcd8fdd8ef4edb16ca9d0c0a094610a3b2d78624c73a6d3545
7
+ data.tar.gz: d71724de93ea68cd9e5f5a4ffd32f8995664dd7d34897ab8a9131eed797a9d0c976e2e402194ccbac0c8887ae6e6fcc6d278924cc6ba1818185cf7b179ac8a6d
data/README.md CHANGED
@@ -101,3 +101,8 @@ Tests are currently very slow because this is testing rails commands so it boots
101
101
  Thanks for reporting issues, I'll do my best.
102
102
 
103
103
  [![Analytics](https://ga-beacon.appspot.com/UA-93841935-1/github-readme?pixel)](https://github.com/damln/localtower)
104
+
105
+
106
+ ## Deploy
107
+
108
+ gem build localtower.gemspec
@@ -1,9 +1,18 @@
1
1
  <style type="text/css">
2
+ .string { color: green; }
3
+ .number { color: darkorange; }
4
+ .boolean { color: blue; }
5
+ .null { color: magenta; }
6
+ .key { color: red; }
7
+
8
+ .code {
9
+ font: 12px Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
10
+ }
11
+
2
12
  .value {
13
+ padding: 10px;
3
14
  border: 1px solid #cacaca;
4
15
  line-height: 1.2em;
5
- font: 12px Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
6
- padding: 10px;
7
16
  overflow:auto;
8
17
  -moz-background-clip: padding;
9
18
  -webkit-background-clip: padding-box;
@@ -16,6 +25,9 @@
16
25
  }
17
26
 
18
27
  </style>
28
+
29
+
30
+
19
31
  <% content_for :title do %>Logs<% end %>
20
32
 
21
33
  <div class="row">
@@ -26,26 +38,27 @@
26
38
  </div>
27
39
 
28
40
  <div class="content">
29
- <table class="table table-hover table-striped">
41
+ <table class="table">
30
42
  <thead>
31
43
  <th>Variable</th>
32
44
  <th>Value</th>
45
+ <th>Value Type</th>
33
46
  </thead>
34
47
 
35
48
  <tbody data-selector="tbody">
36
- <% @logs.each do |item| %>
37
-
38
- <%
39
- variable = item[:variable]
40
- value = item[:value]
41
- %>
49
+ <% @logs["variables"].each do |item| %>
42
50
 
43
51
  <tr data-selector="tr">
52
+ <td class="code">
53
+ <%= item["name"] %>
54
+ </td>
55
+
44
56
  <td>
45
- <%= variable %>
57
+ <pre class="value json code"><%= Localtower::Plugins::Capture.printable(item["value"]) %></pre>
46
58
  </td>
59
+
47
60
  <td>
48
- <pre class="value"><%= value %></pre>
61
+ <pre class="code"><%= item["klass"] %></pre>
49
62
  </td>
50
63
  </tr>
51
64
  <% end %>
@@ -18,6 +18,29 @@ module Localtower
18
18
  "@_response_body",
19
19
  ]
20
20
 
21
+ class << self
22
+ def printable(content)
23
+ if content.respond_to?(:to_json)
24
+ # content.to_json
25
+ JSON.pretty_generate(content)
26
+ else
27
+ content.to_s
28
+ end
29
+ end
30
+
31
+ def type_of(value)
32
+ if value.instance_of?(Float); return Float.to_s; end;
33
+ if value.instance_of?(Integer); return Integer.to_s; end;
34
+ if value.instance_of?(String); return String.to_s; end;
35
+ if value.instance_of?(Array); return Array.to_s; end;
36
+ if value.instance_of?(Hash); return Hash.to_s; end;
37
+ if value.instance_of?(ApplicationController); return ApplicationController.to_s; end;
38
+ if value.instance_of?(NilClass); return NilClass.to_s; end;
39
+
40
+ nil
41
+ end
42
+ end
43
+
21
44
  def initialize(context = nil, context_binding = nil)
22
45
  @context = context
23
46
  @context_binding = context_binding
@@ -25,27 +48,15 @@ module Localtower
25
48
 
26
49
  def logs
27
50
  content = File.open(LOG_FILE).read
28
- return [] unless content.present?
51
+ return {"variables" => []} unless content.present?
29
52
 
30
53
  data = JSON.parse(content)
31
-
32
- data.map do |key, value|
33
- if value.respond_to?(:to_json)
34
- value = JSON.pretty_generate(value)
35
- end
36
-
37
- {
38
- variable: key,
39
- value: value,
40
- }
41
- end
42
54
  end
43
55
 
44
56
  def my_logger
45
57
  @@my_logger ||= Logger.new(LOG_FILE)
46
58
  @@my_logger.formatter = proc do |severity, datetime, progname, msg|
47
59
  "#{msg}\n"
48
- # "[#{datetime}] | #{msg}\n"
49
60
  end
50
61
 
51
62
  @@my_logger
@@ -54,37 +65,74 @@ module Localtower
54
65
  def values
55
66
  hash = {}
56
67
 
68
+ a = @context.send(:caller)[1] # xx/xx/app/controllers/clients/events_controller.rb:57:in `new'
69
+ a = a.split(Rails.root.to_s).last # events_controller.rb:57:in `new'
70
+ a = a.split("\:")
71
+
72
+ file = a[0].strip
73
+ line_number = a[1].strip
74
+ method = a[2].strip.gsub("in \`", "").gsub("\'", "")
75
+
76
+ hash["class"] = self.klass_name
77
+ hash["method"] = "#{file}##{method}:#{line_number}"
78
+
79
+ variables = []
80
+
57
81
  @context_binding.local_variables.each do |var|
58
82
  next if EXCLUDE_INSTANCE_VARIABLES.include?(var.to_s)
59
- hash[var] = @context_binding.local_variable_get(var)
60
83
 
61
- if hash[var].is_a?(ActiveRecord::AssociationRelation)
62
- hash["count_#{var}"] = hash[var].count
84
+ value = @context_binding.local_variable_get(var)
85
+ klass = self.class.type_of(value)
86
+
87
+ variables << {
88
+ name: var,
89
+ value: value,
90
+ klass: klass
91
+ }
92
+
93
+ if value.is_a?(ActiveRecord::AssociationRelation) and value.respond_to?(:count)
94
+ variables << {
95
+ name: "#{var}_count",
96
+ value: value.count,
97
+ klass: nil
98
+ }
63
99
  end
64
100
  end
65
101
 
66
102
  @context.instance_variables.each do |var|
67
103
  next if EXCLUDE_INSTANCE_VARIABLES.include?(var.to_s)
68
104
 
69
- Rails.logger.debug("-------------var")
70
- Rails.logger.debug(var)
105
+ value = @context.instance_variable_get(var.to_sym)
106
+ klass = self.class.type_of(value)
71
107
 
72
- hash[var] = @context.instance_variable_get(var)
108
+ variables << {
109
+ name: var,
110
+ value: value,
111
+ klass: klass
112
+ }
73
113
 
74
- if hash[var].is_a?(ActiveRecord::AssociationRelation)
75
- hash["count_#{var}"] = hash[var].count
114
+ if value.is_a?(ActiveRecord::AssociationRelation) and value.respond_to?(:count)
115
+ variables << {
116
+ name: "#{var}_count",
117
+ value: value.count,
118
+ klass: nil
119
+ }
76
120
  end
77
121
  end
78
122
 
123
+ hash["variables"] = variables
124
+
79
125
  hash
80
126
  end
81
127
 
82
128
  def klass_name
83
- if @context.class == "Class"
129
+ value = if @context.class == "Class"
84
130
  @context
85
131
  else
86
132
  @context.class
87
133
  end
134
+
135
+ value.to_s
88
136
  end
89
137
 
90
138
  # def context_caller
@@ -1,3 +1,3 @@
1
1
  module Localtower
2
- VERSION = '0.1.9'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/public/js/app.js CHANGED
@@ -2,10 +2,16 @@ window.MainApp = {};
2
2
 
3
3
  MainApp = {
4
4
  init: function() {
5
-
6
5
  },
7
6
 
8
7
  ready: function() {
8
+
9
+ $(".json").each(function() {
10
+ var $el = $(this);
11
+ var done = MainApp.syntaxHighlight($el.text());
12
+ $el.html(done);
13
+ });
14
+
9
15
  MainApp.whenActionOnElement("click", "duplicate", function(e) {
10
16
  e.preventDefault();
11
17
  MainApp.duplicateLine();
@@ -41,7 +47,28 @@ MainApp = {
41
47
  });
42
48
  },
43
49
 
44
- // INSTANCE
50
+ // INSTANCE --------------------------------------------------
51
+
52
+ syntaxHighlight: function(json) {
53
+ json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
54
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
55
+ var cls = 'number';
56
+ if (/^"/.test(match)) {
57
+ if (/:$/.test(match)) {
58
+ cls = 'key';
59
+ } else {
60
+ cls = 'string';
61
+ }
62
+ } else if (/true|false/.test(match)) {
63
+ cls = 'boolean';
64
+ } else if (/null/.test(match)) {
65
+ cls = 'null';
66
+ }
67
+ return '<span class="' + cls + '">' + match + '</span>';
68
+ });
69
+ },
70
+
71
+
45
72
 
46
73
  // This is a little bit dirty but it works well for the moment:
47
74
  // We dynamically show/hide fields
@@ -95,9 +122,10 @@ MainApp = {
95
122
 
96
123
  nullable_input,
97
124
  nullable_label,
98
- ], function(i, el) {
99
- el.hide();
100
- });
125
+ ],
126
+ function(i, el) {
127
+ el.hide();
128
+ });
101
129
 
102
130
  var mapping = {
103
131
  add_column: [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localtower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Le Nouaille