helping_hand 0.1.1 → 0.1.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: 9b45c6883bed2978de62c8530115267e2c6c169c
4
- data.tar.gz: 038a7096844055ea62f8b3e607c1263289d4750f
3
+ metadata.gz: acc07a05586adc12af8e6682f46d9b23bf68aaf8
4
+ data.tar.gz: 23e8cf66c4f3a91363d3d3262bb2e275775e13c1
5
5
  SHA512:
6
- metadata.gz: d05aa0e0a801436ff05fc4b1d4ebe7477cabc000aa0209dbac43188e286c26c59a6867bcdf651418df9e447671edf45a706b4fd57f55831a5965cc8b086798a7
7
- data.tar.gz: 6f9f68bcd54d7baacd6bdc19d3e5b7781fb7d0944dd9fc9a267d4f024dac20d205373ffeb70cadf9ef1e709fbbc314820d999c93aef311074aa464f97b3065d9
6
+ metadata.gz: 630281e49f49512be003afc347349e30af17dced1d12680887d6424dd3c40ffdd0e53257b5a858d1e04acaf59bb84367bd8911a6614e18c8c3c53217c066e077
7
+ data.tar.gz: 57daeddab3e7142fd5ba11d6102cadafa08c9fa2ce3157bbe3a4b43e9e29364886fc73c543e705245ed4b90f2d78d1d1af784b81dcc5556ba214983ca8b756b4
@@ -1,8 +1,25 @@
1
1
  require "helping_hand/version"
2
2
 
3
3
  # Override the error templates path from Rails to serve our modified versions
4
- ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH = File.expand_path('../templates', __FILE__)
4
+ ActionDispatch::DebugExceptions.send(:remove_const, :RESCUES_TEMPLATE_PATH)
5
+ ActionDispatch::DebugExceptions.const_set(:RESCUES_TEMPLATE_PATH, File.expand_path('../templates', __FILE__))
5
6
 
6
7
  module HelpingHand
7
- HOST = "https://helpinghand-rails.herokuapp.com/"
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.config
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration) if block_given?
15
+ self.configuration
16
+ end
17
+
18
+ class Configuration
19
+ attr_accessor :host
20
+
21
+ def initialize
22
+ @host = "https://helpinghand-rails.herokuapp.com/"
23
+ end
24
+ end
8
25
  end
@@ -1,3 +1,3 @@
1
1
  module HelpingHand
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -5,8 +5,20 @@
5
5
  <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%= @exception.describe_blame %></code></pre>
6
6
  <% end %>
7
7
 
8
+ <%
9
+ clean_params = @request.filtered_parameters.clone
10
+ clean_params.delete("action")
11
+ clean_params.delete("controller")
12
+
13
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
14
+
15
+ def debug_hash(object)
16
+ object.to_hash.sort_by { |k, _| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
17
+ end unless self.class.method_defined?(:debug_hash)
18
+ %>
19
+
8
20
  <h2 style="margin-top: 30px">Request</h2>
9
- <p><b>Parameters</b>:</p> <pre><%= debug_params(@request.filtered_parameters) %></pre>
21
+ <p><b>Parameters</b>:</p> <pre><%= request_dump %></pre>
10
22
 
11
23
  <div class="details">
12
24
  <div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div>
@@ -19,4 +31,4 @@
19
31
  </div>
20
32
 
21
33
  <h2 style="margin-top: 30px">Response</h2>
22
- <p><b>Headers</b>:</p> <pre><%= debug_headers(defined?(@response) ? @response.headers : {}) %></pre>
34
+ <p><b>Headers</b>:</p> <pre><%= defined?(@response) ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre>
@@ -177,7 +177,7 @@
177
177
  </div>
178
178
 
179
179
  <div class="flex-column">
180
- <iframe src="<%= HelpingHand::HOST %>/exceptions/<%= URI.escape @exception.original_exception.class.to_s %>/messages/<%== URI.escape @exception.message %>/record">
180
+ <iframe src="<%= HelpingHand.config.host %>/exceptions/<%= URI.escape @exception.original_exception.class.to_s %>/messages/<%== URI.escape @exception.message %>/record">
181
181
  </iframe>
182
182
  </div>
183
183
  </div>
@@ -4,13 +4,13 @@
4
4
  <%= route[:name] %><span class='helper'>_path</span>
5
5
  <% end %>
6
6
  </td>
7
- <td>
7
+ <td data-route-verb='<%= route[:verb] %>'>
8
8
  <%= route[:verb] %>
9
9
  </td>
10
- <td data-route-path='<%= route[:path] %>'>
10
+ <td data-route-path='<%= route[:path] %>' data-regexp='<%= route[:regexp] %>'>
11
11
  <%= route[:path] %>
12
12
  </td>
13
- <td>
14
- <%=simple_format route[:reqs] %>
13
+ <td data-route-reqs='<%= route[:reqs] %>'>
14
+ <%= route[:reqs] %>
15
15
  </td>
16
16
  </tr>
@@ -81,87 +81,92 @@
81
81
  </table>
82
82
 
83
83
  <script type='text/javascript'>
84
- // support forEarch iterator on NodeList
85
- NodeList.prototype.forEach = Array.prototype.forEach;
84
+ // Iterates each element through a function
85
+ function each(elems, func) {
86
+ if (!elems instanceof Array) { elems = [elems]; }
87
+ for (var i = 0, len = elems.length; i < len; i++) {
88
+ func(elems[i]);
89
+ }
90
+ }
91
+
92
+ // Sets innerHTML for an element
93
+ function setContent(elem, text) {
94
+ elem.innerHTML = text;
95
+ }
86
96
 
87
97
  // Enables path search functionality
88
98
  function setupMatchPaths() {
89
- // Check if there are any matched results in a section
90
- function checkNoMatch(section, noMatchText) {
91
- if (section.children.length <= 1) {
92
- section.innerHTML += noMatchText;
93
- }
99
+ // Check if the user input (sanitized as a path) matches the regexp data attribute
100
+ function checkExactMatch(section, elem, value) {
101
+ var string = sanitizePath(value),
102
+ regexp = elem.getAttribute("data-regexp");
103
+
104
+ showMatch(string, regexp, section, elem);
94
105
  }
95
106
 
96
- // get JSON from url and invoke callback with result
97
- function getJSON(url, success) {
98
- var xhr = new XMLHttpRequest();
99
- xhr.open('GET', url);
100
- xhr.onload = function() {
101
- if (this.status == 200)
102
- success(JSON.parse(this.response));
103
- };
104
- xhr.send();
107
+ // Check if the route path data attribute contains the user input
108
+ function checkFuzzyMatch(section, elem, value) {
109
+ var string = elem.getAttribute("data-route-path"),
110
+ regexp = value;
111
+
112
+ showMatch(string, regexp, section, elem);
105
113
  }
106
114
 
107
- function delayedKeyup(input, callback) {
108
- var timeout;
109
- input.onkeyup = function(){
110
- if (timeout) clearTimeout(timeout);
111
- timeout = setTimeout(callback, 300);
115
+ // Display the parent <tr> element in the appropriate section when there's a match
116
+ function showMatch(string, regexp, section, elem) {
117
+ if(string.match(RegExp(regexp))) {
118
+ section.appendChild(elem.parentNode.cloneNode(true));
112
119
  }
113
120
  }
114
121
 
115
- // remove params or fragments
122
+ // Check if there are any matched results in a section
123
+ function checkNoMatch(section, defaultText, noMatchText) {
124
+ if (section.innerHTML === defaultText) {
125
+ setContent(section, defaultText + noMatchText);
126
+ }
127
+ }
128
+
129
+ // Ensure path always starts with a slash "/" and remove params or fragments
116
130
  function sanitizePath(path) {
117
- return path.replace(/[#?].*/, '');
131
+ var path = path.charAt(0) == '/' ? path : "/" + path;
132
+ return path.replace(/\#.*|\?.*/, '');
118
133
  }
119
134
 
120
- var pathElements = document.querySelectorAll('#route_table [data-route-path]'),
121
- searchElem = document.querySelector('#search'),
122
- exactSection = document.querySelector('#exact_matches'),
123
- fuzzySection = document.querySelector('#fuzzy_matches');
135
+ var regexpElems = document.querySelectorAll('#route_table [data-regexp]'),
136
+ searchElem = document.querySelector('#search'),
137
+ exactMatches = document.querySelector('#exact_matches'),
138
+ fuzzyMatches = document.querySelector('#fuzzy_matches');
124
139
 
125
140
  // Remove matches when no search value is present
126
141
  searchElem.onblur = function(e) {
127
142
  if (searchElem.value === "") {
128
- exactSection.innerHTML = "";
129
- fuzzySection.innerHTML = "";
143
+ setContent(exactMatches, "");
144
+ setContent(fuzzyMatches, "");
130
145
  }
131
146
  }
132
147
 
133
148
  // On key press perform a search for matching paths
134
- delayedKeyup(searchElem, function() {
135
- var path = sanitizePath(searchElem.value),
136
- defaultExactMatch = '<tr><th colspan="4">Paths Matching (' + path +'):</th></tr>',
137
- defaultFuzzyMatch = '<tr><th colspan="4">Paths Containing (' + path +'):</th></tr>',
149
+ searchElem.onkeyup = function(e){
150
+ var userInput = searchElem.value,
151
+ defaultExactMatch = '<tr><th colspan="4">Paths Matching (' + escape(sanitizePath(userInput)) +'):</th></tr>',
152
+ defaultFuzzyMatch = '<tr><th colspan="4">Paths Containing (' + escape(userInput) +'):</th></tr>',
138
153
  noExactMatch = '<tr><th colspan="4">No Exact Matches Found</th></tr>',
139
154
  noFuzzyMatch = '<tr><th colspan="4">No Fuzzy Matches Found</th></tr>';
140
155
 
141
- if (!path)
142
- return searchElem.onblur();
143
-
144
- getJSON('/rails/info/routes?path=' + path, function(matches){
145
- // Clear out results section
146
- exactSection.innerHTML = defaultExactMatch;
147
- fuzzySection.innerHTML = defaultFuzzyMatch;
148
-
149
- // Display exact matches and fuzzy matches
150
- pathElements.forEach(function(elem) {
151
- var elemPath = elem.getAttribute('data-route-path');
152
-
153
- if (matches['exact'].indexOf(elemPath) != -1)
154
- exactSection.appendChild(elem.parentNode.cloneNode(true));
156
+ // Clear out results section
157
+ setContent(exactMatches, defaultExactMatch);
158
+ setContent(fuzzyMatches, defaultFuzzyMatch);
155
159
 
156
- if (matches['fuzzy'].indexOf(elemPath) != -1)
157
- fuzzySection.appendChild(elem.parentNode.cloneNode(true));
158
- })
159
-
160
- // Display 'No Matches' message when no matches are found
161
- checkNoMatch(exactSection, noExactMatch);
162
- checkNoMatch(fuzzySection, noFuzzyMatch);
160
+ // Display exact matches and fuzzy matches
161
+ each(regexpElems, function(elem) {
162
+ checkExactMatch(exactMatches, elem, userInput);
163
+ checkFuzzyMatch(fuzzyMatches, elem, userInput);
163
164
  })
164
- })
165
+
166
+ // Display 'No Matches' message when no matches are found
167
+ checkNoMatch(exactMatches, defaultExactMatch, noExactMatch);
168
+ checkNoMatch(fuzzyMatches, defaultFuzzyMatch, noFuzzyMatch);
169
+ }
165
170
  }
166
171
 
167
172
  // Enables functionality to toggle between `_path` and `_url` helper suffixes
@@ -169,20 +174,19 @@
169
174
 
170
175
  // Sets content for each element
171
176
  function setValOn(elems, val) {
172
- elems.forEach(function(elem) {
173
- elem.innerHTML = val;
177
+ each(elems, function(elem) {
178
+ setContent(elem, val);
174
179
  });
175
180
  }
176
181
 
177
182
  // Sets onClick event for each element
178
183
  function onClick(elems, func) {
179
- elems.forEach(function(elem) {
184
+ each(elems, function(elem) {
180
185
  elem.onclick = func;
181
186
  });
182
187
  }
183
188
 
184
189
  var toggleLinks = document.querySelectorAll('#route_table [data-route-helper]');
185
-
186
190
  onClick(toggleLinks, function(){
187
191
  var helperTxt = this.getAttribute("data-route-helper"),
188
192
  helperElems = document.querySelectorAll('[data-route-name] span.helper');
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helping_hand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver