helping_hand 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9e32012021e5110e5597dee189f4bf078f652c3
4
+ data.tar.gz: 28d3a569ab5b797c1bbce21c6f59beeb326b3b9d
5
+ SHA512:
6
+ metadata.gz: 47f720aea466953e8bd3bafbba20f4a0954b8849bae46f5325cb413731071c064e56a400991860ab22d100c8bc10a494bcb4db905ad94422af04112fcec3c9b1
7
+ data.tar.gz: c215feb49cf5f575d475a9f841767a988b8edfa1763023f791983b36ed9e313a21974c89eb52b6bd25ae3d797009d07bb48bda25f1d2d6cba48432e22b1f9996
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in helping_hand.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Oliver
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # HelpingHand
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/helping_hand`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'helping_hand'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install helping_hand
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/helping_hand/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "helping_hand"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'helping_hand/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "helping_hand"
8
+ spec.version = HelpingHand::VERSION
9
+ spec.authors = ["Chris Oliver"]
10
+ spec.email = ["excid3@gmail.com"]
11
+
12
+ spec.summary = %q{Embedded help in your Ruby on Rails error pages for learning how to fix bugs when they arise.}
13
+ spec.description = %q{Embedded help in your Ruby on Rails error pages for learning how to fix bugs when they arise.}
14
+ spec.homepage = "https://helpinghand-rails.herokuapp.com/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,3 @@
1
+ module HelpingHand
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "helping_hand/version"
2
+ require "helping_hand/railtie"
3
+
4
+ # Override the error templates path from Rails to serve our modified versions
5
+ ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH = File.expand_path('../templates', __FILE__)
6
+
7
+ module HelpingHand
8
+ HOST = "https://helpinghand-rails.herokuapp.com/"
9
+ end
@@ -0,0 +1,22 @@
1
+ <% unless @exception.blamed_files.blank? %>
2
+ <% if (hide = @exception.blamed_files.length > 8) %>
3
+ <a href="#" onclick="return toggleTrace()">Toggle blamed files</a>
4
+ <% end %>
5
+ <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%= @exception.describe_blame %></code></pre>
6
+ <% end %>
7
+
8
+ <h2 style="margin-top: 30px">Request</h2>
9
+ <p><b>Parameters</b>:</p> <pre><%= debug_params(@request.filtered_parameters) %></pre>
10
+
11
+ <div class="details">
12
+ <div class="summary"><a href="#" onclick="return toggleSessionDump()">Toggle session dump</a></div>
13
+ <div id="session_dump" style="display:none"><pre><%= debug_hash @request.session %></pre></div>
14
+ </div>
15
+
16
+ <div class="details">
17
+ <div class="summary"><a href="#" onclick="return toggleEnvDump()">Toggle env dump</a></div>
18
+ <div id="env_dump" style="display:none"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div>
19
+ </div>
20
+
21
+ <h2 style="margin-top: 30px">Response</h2>
22
+ <p><b>Headers</b>:</p> <pre><%= debug_headers(defined?(@response) ? @response.headers : {}) %></pre>
@@ -0,0 +1,23 @@
1
+ <%
2
+ clean_params = @request.filtered_parameters.clone
3
+ clean_params.delete("action")
4
+ clean_params.delete("controller")
5
+
6
+ request_dump = clean_params.empty? ? 'None' : clean_params.inspect.gsub(',', ",\n")
7
+
8
+ def debug_hash(object)
9
+ object.to_hash.sort_by { |k, _| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
10
+ end unless self.class.method_defined?(:debug_hash)
11
+ %>
12
+
13
+ Request parameters
14
+ <%= request_dump %>
15
+
16
+ Session dump
17
+ <%= debug_hash @request.session %>
18
+
19
+ Env dump
20
+ <%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %>
21
+
22
+ Response headers
23
+ <%= defined?(@response) ? @response.headers.inspect.gsub(',', ",\n") : 'None' %>
@@ -0,0 +1,27 @@
1
+ <% @source_extracts.each_with_index do |source_extract, index| %>
2
+ <% if source_extract[:code] %>
3
+ <div class="source <%="hidden" if @show_source_idx != index%>" id="frame-source-<%=index%>">
4
+ <div class="info">
5
+ Extracted source (around line <strong>#<%= source_extract[:line_number] %></strong>):
6
+ </div>
7
+ <div class="data">
8
+ <table cellpadding="0" cellspacing="0" class="lines">
9
+ <tr>
10
+ <td>
11
+ <pre class="line_numbers">
12
+ <% source_extract[:code].each_key do |line_number| %>
13
+ <span><%= line_number -%></span>
14
+ <% end %>
15
+ </pre>
16
+ </td>
17
+ <td width="100%">
18
+ <pre>
19
+ <% source_extract[:code].each do |line, source| -%><div class="line<%= " active" if line == source_extract[:line_number] -%>"><%= source -%></div><% end -%>
20
+ </pre>
21
+ </td>
22
+ </tr>
23
+ </table>
24
+ </div>
25
+ </div>
26
+ <% end %>
27
+ <% end %>
@@ -0,0 +1,52 @@
1
+ <% names = @traces.keys %>
2
+
3
+ <p><code>Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %></code></p>
4
+
5
+ <div id="traces">
6
+ <% names.each do |name| %>
7
+ <%
8
+ show = "show('#{name.gsub(/\s/, '-')}');"
9
+ hide = (names - [name]).collect {|hide_name| "hide('#{hide_name.gsub(/\s/, '-')}');"}
10
+ %>
11
+ <a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
12
+ <% end %>
13
+
14
+ <% @traces.each do |name, trace| %>
15
+ <div id="<%= name.gsub(/\s/, '-') %>" style="display: <%= (name == @trace_to_show) ? 'block' : 'none' %>;">
16
+ <pre><code><% trace.each do |frame| %><a class="trace-frames" data-frame-id="<%= frame[:id] %>" href="#"><%= frame[:trace] %></a><br><% end %></code></pre>
17
+ </div>
18
+ <% end %>
19
+
20
+ <script type="text/javascript">
21
+ var traceFrames = document.getElementsByClassName('trace-frames');
22
+ var selectedFrame, currentSource = document.getElementById('frame-source-0');
23
+
24
+ // Add click listeners for all stack frames
25
+ for (var i = 0; i < traceFrames.length; i++) {
26
+ traceFrames[i].addEventListener('click', function(e) {
27
+ e.preventDefault();
28
+ var target = e.target;
29
+ var frame_id = target.dataset.frameId;
30
+
31
+ if (selectedFrame) {
32
+ selectedFrame.className = selectedFrame.className.replace("selected", "");
33
+ }
34
+
35
+ target.className += " selected";
36
+ selectedFrame = target;
37
+
38
+ // Change the extracted source code
39
+ changeSourceExtract(frame_id);
40
+ });
41
+
42
+ function changeSourceExtract(frame_id) {
43
+ var el = document.getElementById('frame-source-' + frame_id);
44
+ if (currentSource && el) {
45
+ currentSource.className += " hidden";
46
+ el.className = el.className.replace(" hidden", "");
47
+ currentSource = el;
48
+ }
49
+ }
50
+ }
51
+ </script>
52
+ </div>
@@ -0,0 +1,9 @@
1
+ Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %>
2
+
3
+ <% @traces.each do |name, trace| %>
4
+ <% if trace.any? %>
5
+ <%= name %>
6
+ <%= trace.map { |t| t[:trace] }.join("\n") %>
7
+
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <header>
2
+ <h1>
3
+ <%= @exception.class.to_s %>
4
+ <% if @request.parameters['controller'] %>
5
+ in <%= @request.parameters['controller'].camelize %>Controller<% if @request.parameters['action'] %>#<%= @request.parameters['action'] %><% end %>
6
+ <% end %>
7
+ </h1>
8
+ </header>
9
+
10
+ <div id="container">
11
+ <h2><%= h @exception.message %></h2>
12
+
13
+ <%= render template: "rescues/_source" %>
14
+ <%= render template: "rescues/_trace" %>
15
+ <%= render template: "rescues/_request_and_response" %>
16
+ </div>
@@ -0,0 +1,9 @@
1
+ <%= @exception.class.to_s %><%
2
+ if @request.parameters['controller']
3
+ %> in <%= @request.parameters['controller'].camelize %>Controller<% if @request.parameters['action'] %>#<%= @request.parameters['action'] %><% end %>
4
+ <% end %>
5
+
6
+ <%= @exception.message %>
7
+ <%= render template: "rescues/_source" %>
8
+ <%= render template: "rescues/_trace" %>
9
+ <%= render template: "rescues/_request_and_response" %>
@@ -0,0 +1,186 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Action Controller: Exception caught</title>
6
+ <style>
7
+ body {
8
+ background-color: #FAFAFA;
9
+ color: #333;
10
+ margin: 0px;
11
+ }
12
+
13
+ body, p, ol, ul, td {
14
+ font-family: helvetica, verdana, arial, sans-serif;
15
+ font-size: 13px;
16
+ line-height: 18px;
17
+ }
18
+
19
+ pre {
20
+ font-size: 11px;
21
+ white-space: pre-wrap;
22
+ }
23
+
24
+ pre.box {
25
+ border: 1px solid #EEE;
26
+ padding: 10px;
27
+ margin: 0px;
28
+ max-width: 958px;
29
+ }
30
+
31
+ header {
32
+ color: #F0F0F0;
33
+ background: #C52F24;
34
+ padding: 0.5em 1.5em;
35
+ }
36
+
37
+ h1 {
38
+ margin: 0.2em 0;
39
+ line-height: 1.1em;
40
+ font-size: 2em;
41
+ }
42
+
43
+ h2 {
44
+ color: #C52F24;
45
+ line-height: 25px;
46
+ }
47
+
48
+ .details {
49
+ border: 1px solid #D0D0D0;
50
+ border-radius: 4px;
51
+ margin: 1em 0px;
52
+ display: block;
53
+ max-width: 978px;
54
+ }
55
+
56
+ .summary {
57
+ padding: 8px 15px;
58
+ border-bottom: 1px solid #D0D0D0;
59
+ display: block;
60
+ }
61
+
62
+ .details pre {
63
+ margin: 5px;
64
+ border: none;
65
+ }
66
+
67
+ #container {
68
+ box-sizing: border-box;
69
+ width: 100%;
70
+ padding: 0 1.5em;
71
+ }
72
+
73
+ .source * {
74
+ margin: 0px;
75
+ padding: 0px;
76
+ }
77
+
78
+ .source {
79
+ border: 1px solid #D9D9D9;
80
+ background: #ECECEC;
81
+ max-width: 978px;
82
+ }
83
+
84
+ .source pre {
85
+ padding: 10px 0px;
86
+ border: none;
87
+ }
88
+
89
+ .source .data {
90
+ font-size: 80%;
91
+ overflow: auto;
92
+ background-color: #FFF;
93
+ }
94
+
95
+ .info {
96
+ padding: 0.5em;
97
+ }
98
+
99
+ .source .data .line_numbers {
100
+ background-color: #ECECEC;
101
+ color: #AAA;
102
+ padding: 1em .5em;
103
+ border-right: 1px solid #DDD;
104
+ text-align: right;
105
+ }
106
+
107
+ .line {
108
+ padding-left: 10px;
109
+ }
110
+
111
+ .line:hover {
112
+ background-color: #F6F6F6;
113
+ }
114
+
115
+ .line.active {
116
+ background-color: #FFCCCC;
117
+ }
118
+
119
+ .hidden {
120
+ display: none;
121
+ }
122
+
123
+ a { color: #980905; }
124
+ a:visited { color: #666; }
125
+ a.trace-frames { color: #666; }
126
+ a:hover { color: #C52F24; }
127
+ a.trace-frames.selected { color: #C52F24 }
128
+
129
+ .container {
130
+ display: -webkit-flex;
131
+ display: flex;
132
+ }
133
+ .flex-column {
134
+ -webkit-flex: 1;
135
+ flex: 1;
136
+ position: relative;
137
+ }
138
+
139
+ iframe {
140
+ border: none;
141
+ position: absolute;
142
+ height: 100%;
143
+ width: 100%;
144
+ }
145
+
146
+ <%= yield :style %>
147
+ </style>
148
+
149
+ <script>
150
+ var toggle = function(id) {
151
+ var s = document.getElementById(id).style;
152
+ s.display = s.display == 'none' ? 'block' : 'none';
153
+ return false;
154
+ }
155
+ var show = function(id) {
156
+ document.getElementById(id).style.display = 'block';
157
+ }
158
+ var hide = function(id) {
159
+ document.getElementById(id).style.display = 'none';
160
+ }
161
+ var toggleTrace = function() {
162
+ return toggle('blame_trace');
163
+ }
164
+ var toggleSessionDump = function() {
165
+ return toggle('session_dump');
166
+ }
167
+ var toggleEnvDump = function() {
168
+ return toggle('env_dump');
169
+ }
170
+ </script>
171
+ </head>
172
+ <body>
173
+
174
+ <div class="container">
175
+ <div class="flex-column">
176
+ <%= yield %>
177
+ </div>
178
+
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">
181
+ </iframe>
182
+ </div>
183
+ </div>
184
+
185
+ </body>
186
+ </html>
@@ -0,0 +1,11 @@
1
+ <header>
2
+ <h1>Template is missing</h1>
3
+ </header>
4
+
5
+ <div id="container">
6
+ <h2><%= h @exception.message %></h2>
7
+
8
+ <%= render template: "rescues/_source" %>
9
+ <%= render template: "rescues/_trace" %>
10
+ <%= render template: "rescues/_request_and_response" %>
11
+ </div>
@@ -0,0 +1,3 @@
1
+ Template is missing
2
+
3
+ <%= @exception.message %>
@@ -0,0 +1,32 @@
1
+ <header>
2
+ <h1>Routing Error</h1>
3
+ </header>
4
+ <div id="container">
5
+ <h2><%= h @exception.message %></h2>
6
+ <% unless @exception.failures.empty? %>
7
+ <p>
8
+ <h2>Failure reasons:</h2>
9
+ <ol>
10
+ <% @exception.failures.each do |route, reason| %>
11
+ <li><code><%= route.inspect.delete('\\') %></code> failed because <%= reason.downcase %></li>
12
+ <% end %>
13
+ </ol>
14
+ </p>
15
+ <% end %>
16
+
17
+ <%= render template: "rescues/_trace" %>
18
+
19
+ <% if @routes_inspector %>
20
+ <h2>
21
+ Routes
22
+ </h2>
23
+
24
+ <p>
25
+ Routes match in priority from top to bottom
26
+ </p>
27
+
28
+ <%= @routes_inspector.format(ActionDispatch::Routing::HtmlTableFormatter.new(self)) %>
29
+ <% end %>
30
+
31
+ <%= render template: "rescues/_request_and_response" %>
32
+ </div>
@@ -0,0 +1,11 @@
1
+ Routing Error
2
+
3
+ <%= @exception.message %>
4
+ <% unless @exception.failures.empty? %>
5
+ Failure reasons:
6
+ <% @exception.failures.each do |route, reason| %>
7
+ - <%= route.inspect.delete('\\') %></code> failed because <%= reason.downcase %>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <%= render template: "rescues/_trace", format: :text %>
@@ -0,0 +1,20 @@
1
+ <header>
2
+ <h1>
3
+ <%= @exception.original_exception.class.to_s %> in
4
+ <%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %>
5
+ </h1>
6
+ </header>
7
+
8
+ <div id="container">
9
+ <p>
10
+ Showing <i><%= @exception.file_name %></i> where line <b>#<%= @exception.line_number %></b> raised:
11
+ </p>
12
+ <pre><code><%= h @exception.message %></code></pre>
13
+
14
+ <%= render template: "rescues/_source" %>
15
+
16
+ <p><%= @exception.sub_template_message %></p>
17
+
18
+ <%= render template: "rescues/_trace" %>
19
+ <%= render template: "rescues/_request_and_response" %>
20
+ </div>
@@ -0,0 +1,7 @@
1
+ <%= @exception.original_exception.class.to_s %> in <%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %>
2
+
3
+ Showing <%= @exception.file_name %> where line #<%= @exception.line_number %> raised:
4
+ <%= @exception.message %>
5
+ <%= @exception.sub_template_message %>
6
+ <%= render template: "rescues/_trace", format: :text %>
7
+ <%= render template: "rescues/_request_and_response", format: :text %>
@@ -0,0 +1,6 @@
1
+ <header>
2
+ <h1>Unknown action</h1>
3
+ </header>
4
+ <div id="container">
5
+ <h2><%= h @exception.message %></h2>
6
+ </div>
@@ -0,0 +1,3 @@
1
+ Unknown action
2
+
3
+ <%= @exception.message %>
@@ -0,0 +1,16 @@
1
+ <tr class='route_row' data-helper='path'>
2
+ <td data-route-name='<%= route[:name] %>'>
3
+ <% if route[:name].present? %>
4
+ <%= route[:name] %><span class='helper'>_path</span>
5
+ <% end %>
6
+ </td>
7
+ <td>
8
+ <%= route[:verb] %>
9
+ </td>
10
+ <td data-route-path='<%= route[:path] %>'>
11
+ <%= route[:path] %>
12
+ </td>
13
+ <td>
14
+ <%=simple_format route[:reqs] %>
15
+ </td>
16
+ </tr>
@@ -0,0 +1,196 @@
1
+ <% content_for :style do %>
2
+ #route_table {
3
+ margin: 0;
4
+ border-collapse: collapse;
5
+ }
6
+
7
+ #route_table thead tr {
8
+ border-bottom: 2px solid #ddd;
9
+ }
10
+
11
+ #route_table thead tr.bottom {
12
+ border-bottom: none;
13
+ }
14
+
15
+ #route_table thead tr.bottom th {
16
+ padding: 10px 0;
17
+ line-height: 15px;
18
+ }
19
+
20
+ #route_table tbody tr {
21
+ border-bottom: 1px solid #ddd;
22
+ }
23
+
24
+ #route_table tbody tr:nth-child(odd) {
25
+ background: #f2f2f2;
26
+ }
27
+
28
+ #route_table tbody.exact_matches,
29
+ #route_table tbody.fuzzy_matches {
30
+ background-color: LightGoldenRodYellow;
31
+ border-bottom: solid 2px SlateGrey;
32
+ }
33
+
34
+ #route_table tbody.exact_matches tr,
35
+ #route_table tbody.fuzzy_matches tr {
36
+ background: none;
37
+ border-bottom: none;
38
+ }
39
+
40
+ #route_table td {
41
+ padding: 4px 30px;
42
+ }
43
+
44
+ #path_search {
45
+ width: 80%;
46
+ font-size: inherit;
47
+ }
48
+ <% end %>
49
+
50
+ <table id='route_table' class='route_table'>
51
+ <thead>
52
+ <tr>
53
+ <th>Helper</th>
54
+ <th>HTTP Verb</th>
55
+ <th>Path</th>
56
+ <th>Controller#Action</th>
57
+ </tr>
58
+ <tr class='bottom'>
59
+ <th><%# Helper %>
60
+ <%= link_to "Path", "#", 'data-route-helper' => '_path',
61
+ title: "Returns a relative path (without the http or domain)" %> /
62
+ <%= link_to "Url", "#", 'data-route-helper' => '_url',
63
+ title: "Returns an absolute url (with the http and domain)" %>
64
+ </th>
65
+ <th><%# HTTP Verb %>
66
+ </th>
67
+ <th><%# Path %>
68
+ <%= search_field(:path, nil, id: 'search', placeholder: "Path Match") %>
69
+ </th>
70
+ <th><%# Controller#action %>
71
+ </th>
72
+ </tr>
73
+ </thead>
74
+ <tbody class='exact_matches' id='exact_matches'>
75
+ </tbody>
76
+ <tbody class='fuzzy_matches' id='fuzzy_matches'>
77
+ </tbody>
78
+ <tbody>
79
+ <%= yield %>
80
+ </tbody>
81
+ </table>
82
+
83
+ <script type='text/javascript'>
84
+ // support forEarch iterator on NodeList
85
+ NodeList.prototype.forEach = Array.prototype.forEach;
86
+
87
+ // Enables path search functionality
88
+ 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
+ }
94
+ }
95
+
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();
105
+ }
106
+
107
+ function delayedKeyup(input, callback) {
108
+ var timeout;
109
+ input.onkeyup = function(){
110
+ if (timeout) clearTimeout(timeout);
111
+ timeout = setTimeout(callback, 300);
112
+ }
113
+ }
114
+
115
+ // remove params or fragments
116
+ function sanitizePath(path) {
117
+ return path.replace(/[#?].*/, '');
118
+ }
119
+
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');
124
+
125
+ // Remove matches when no search value is present
126
+ searchElem.onblur = function(e) {
127
+ if (searchElem.value === "") {
128
+ exactSection.innerHTML = "";
129
+ fuzzySection.innerHTML = "";
130
+ }
131
+ }
132
+
133
+ // 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>',
138
+ noExactMatch = '<tr><th colspan="4">No Exact Matches Found</th></tr>',
139
+ noFuzzyMatch = '<tr><th colspan="4">No Fuzzy Matches Found</th></tr>';
140
+
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));
155
+
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);
163
+ })
164
+ })
165
+ }
166
+
167
+ // Enables functionality to toggle between `_path` and `_url` helper suffixes
168
+ function setupRouteToggleHelperLinks() {
169
+
170
+ // Sets content for each element
171
+ function setValOn(elems, val) {
172
+ elems.forEach(function(elem) {
173
+ elem.innerHTML = val;
174
+ });
175
+ }
176
+
177
+ // Sets onClick event for each element
178
+ function onClick(elems, func) {
179
+ elems.forEach(function(elem) {
180
+ elem.onclick = func;
181
+ });
182
+ }
183
+
184
+ var toggleLinks = document.querySelectorAll('#route_table [data-route-helper]');
185
+
186
+ onClick(toggleLinks, function(){
187
+ var helperTxt = this.getAttribute("data-route-helper"),
188
+ helperElems = document.querySelectorAll('[data-route-name] span.helper');
189
+
190
+ setValOn(helperElems, helperTxt);
191
+ });
192
+ }
193
+
194
+ setupMatchPaths();
195
+ setupRouteToggleHelperLinks();
196
+ </script>
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: helping_hand
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Oliver
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Embedded help in your Ruby on Rails error pages for learning how to fix
42
+ bugs when they arise.
43
+ email:
44
+ - excid3@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - helping_hand.gemspec
60
+ - lib/helping_hand.rb
61
+ - lib/helping_hand/version.rb
62
+ - lib/templates/rescues/_request_and_response.html.erb
63
+ - lib/templates/rescues/_request_and_response.text.erb
64
+ - lib/templates/rescues/_source.erb
65
+ - lib/templates/rescues/_trace.html.erb
66
+ - lib/templates/rescues/_trace.text.erb
67
+ - lib/templates/rescues/diagnostics.html.erb
68
+ - lib/templates/rescues/diagnostics.text.erb
69
+ - lib/templates/rescues/layout.erb
70
+ - lib/templates/rescues/missing_template.html.erb
71
+ - lib/templates/rescues/missing_template.text.erb
72
+ - lib/templates/rescues/routing_error.html.erb
73
+ - lib/templates/rescues/routing_error.text.erb
74
+ - lib/templates/rescues/template_error.html.erb
75
+ - lib/templates/rescues/template_error.text.erb
76
+ - lib/templates/rescues/unknown_action.html.erb
77
+ - lib/templates/rescues/unknown_action.text.erb
78
+ - lib/templates/routes/_route.html.erb
79
+ - lib/templates/routes/_table.html.erb
80
+ homepage: https://helpinghand-rails.herokuapp.com/
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Embedded help in your Ruby on Rails error pages for learning how to fix bugs
104
+ when they arise.
105
+ test_files: []