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 +4 -4
- data/lib/helping_hand.rb +19 -2
- data/lib/helping_hand/version.rb +1 -1
- data/lib/templates/rescues/_request_and_response.html.erb +14 -2
- data/lib/templates/rescues/layout.erb +1 -1
- data/lib/templates/routes/_route.html.erb +4 -4
- data/lib/templates/routes/_table.html.erb +63 -59
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc07a05586adc12af8e6682f46d9b23bf68aaf8
|
4
|
+
data.tar.gz: 23e8cf66c4f3a91363d3d3262bb2e275775e13c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630281e49f49512be003afc347349e30af17dced1d12680887d6424dd3c40ffdd0e53257b5a858d1e04acaf59bb84367bd8911a6614e18c8c3c53217c066e077
|
7
|
+
data.tar.gz: 57daeddab3e7142fd5ba11d6102cadafa08c9fa2ce3157bbe3a4b43e9e29364886fc73c543e705245ed4b90f2d78d1d1af784b81dcc5556ba214983ca8b756b4
|
data/lib/helping_hand.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
data/lib/helping_hand/version.rb
CHANGED
@@ -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><%=
|
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><%=
|
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
|
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
|
-
<%=
|
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
|
-
//
|
85
|
-
|
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
|
90
|
-
function
|
91
|
-
|
92
|
-
|
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
|
-
//
|
97
|
-
function
|
98
|
-
var
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
//
|
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
|
-
|
131
|
+
var path = path.charAt(0) == '/' ? path : "/" + path;
|
132
|
+
return path.replace(/\#.*|\?.*/, '');
|
118
133
|
}
|
119
134
|
|
120
|
-
var
|
121
|
-
searchElem
|
122
|
-
|
123
|
-
|
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
|
-
|
129
|
-
|
143
|
+
setContent(exactMatches, "");
|
144
|
+
setContent(fuzzyMatches, "");
|
130
145
|
}
|
131
146
|
}
|
132
147
|
|
133
148
|
// On key press perform a search for matching paths
|
134
|
-
|
135
|
-
var
|
136
|
-
defaultExactMatch = '<tr><th colspan="4">Paths Matching (' +
|
137
|
-
defaultFuzzyMatch = '<tr><th colspan="4">Paths Containing (' +
|
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
|
-
|
142
|
-
|
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
|
-
|
157
|
-
|
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
|
173
|
-
elem
|
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
|
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');
|