errship3-bootstrap 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +160 -0
- data/app/assets/javascripts/application.js +7 -0
- data/app/assets/stylesheets/errship3.css +2 -0
- data/app/views/errship3/standard.html.erb +14 -0
- data/config/locales/en.yml +8 -0
- data/config/routes.rb +10 -0
- data/lib/errship3.rb +63 -0
- data/lib/generators/errship3/templates/standard.html.erb +14 -0
- data/lib/generators/errship3/view_generator.rb +17 -0
- data/lib/rescuers/active_record.rb +11 -0
- data/lib/rescuers/mongo_mapper.rb +11 -0
- data/lib/rescuers/mongoid.rb +11 -0
- metadata +150 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Logan Koester
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
= => errship3
|
2
|
+
|
3
|
+
The static error pages Rails comes with are nice for getting started - you can't
|
4
|
+
break them, no matter what. But without your layout and navigation wrapped around
|
5
|
+
them, they create a frustrating trap for your users.
|
6
|
+
|
7
|
+
The obvious solution is to render your layout into the static file, but what happens
|
8
|
+
when you make a change?
|
9
|
+
|
10
|
+
Worse, what if you run a network of many Rails applications? Should they share one
|
11
|
+
error page style? Should they all have their own?
|
12
|
+
|
13
|
+
You could hire your nephew to keep them all up to date... or you can use Errship3.
|
14
|
+
|
15
|
+
Errship3 is a Rails 3.1 engine for rendering error pages inside your layout. It supports
|
16
|
+
i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.
|
17
|
+
|
18
|
+
You can also use the flashback method to set an error message and redirect :back safely - if
|
19
|
+
a RedirectBackError is raised, the user is dropped off at the nearest error page and given
|
20
|
+
the flash message anyway.
|
21
|
+
|
22
|
+
Now it will also support twitter bootstrap
|
23
|
+
|
24
|
+
== Installation
|
25
|
+
|
26
|
+
Add this to your Gemfile
|
27
|
+
gem 'errship3', '~> 3.0.1'
|
28
|
+
|
29
|
+
Add this to your ApplicationController
|
30
|
+
class ApplicationController < ActionController::Base
|
31
|
+
include Errship3::Rescuers
|
32
|
+
include Errship3::ActiveRecord::Rescuers # or replace 'ActiveRecord' with MongoMapper, or Mongoid
|
33
|
+
|
34
|
+
You can generate the view file to customize yourself
|
35
|
+
rails g errship3:view
|
36
|
+
this will generate a view file on your app/views/errship3/standard.html.erb
|
37
|
+
|
38
|
+
You can customize it yourself.
|
39
|
+
|
40
|
+
|
41
|
+
Errship3 is ready to go! To test it out in development, you'll need to set
|
42
|
+
|
43
|
+
config.consider_all_requests_local = false
|
44
|
+
|
45
|
+
in your config/environments/development.rb file. Just don't forget to change it back
|
46
|
+
when you want useful debugging output again instead!
|
47
|
+
|
48
|
+
Alternatively, simply point your browser to /error or /not_found to get a taste.
|
49
|
+
|
50
|
+
== Configuration
|
51
|
+
|
52
|
+
Errship3 renders all error pages with a HTTP status of 200 by default. This is
|
53
|
+
done to ensure that the error page is rendered if the web server is configured
|
54
|
+
to intercept errors (e.g. proxy_intercept_errors for nginx). If you want to
|
55
|
+
have the correct status codes for your errors, add the following to an
|
56
|
+
initializer:
|
57
|
+
|
58
|
+
Errship3.status_code_success = false
|
59
|
+
|
60
|
+
== I18n
|
61
|
+
|
62
|
+
If you want to edit the text that is rendered, add the following to your config/locales/*.yml
|
63
|
+
|
64
|
+
en:
|
65
|
+
errship3:
|
66
|
+
'404':
|
67
|
+
title: 'This page does not exist.'
|
68
|
+
description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
|
69
|
+
'500':
|
70
|
+
title: 'An error has occurred.'
|
71
|
+
description: 'This has been reported to our development team. Thank you!'
|
72
|
+
|
73
|
+
...and so forth, for any error code you like.
|
74
|
+
|
75
|
+
== Custom Rescuers
|
76
|
+
|
77
|
+
If you want errship3 to rescue errors from your own custom exception class, you need
|
78
|
+
to add a custom rescuer in your ApplicationController, like so:
|
79
|
+
|
80
|
+
# Render the 404 page
|
81
|
+
rescue_from MyException::SomethingMissing, :with => :render_404_error
|
82
|
+
|
83
|
+
# Render the 500 page
|
84
|
+
rescue_from MyException::SomethingWentWrong, :with => :render_error
|
85
|
+
|
86
|
+
To customize the error for a particular controller or exception class, add a rescuer
|
87
|
+
like this one:
|
88
|
+
|
89
|
+
rescue_from ActiveRecord::RecordNotFound, :with => ->(e){ render_404_error e, 'monkeys' }
|
90
|
+
|
91
|
+
and then add your text for that scope to config/locales/*.yml
|
92
|
+
|
93
|
+
en:
|
94
|
+
errship3:
|
95
|
+
'404':
|
96
|
+
title: 'This page does not exist.'
|
97
|
+
description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
|
98
|
+
monkeys:
|
99
|
+
title: 'They must have escaped'
|
100
|
+
description: 'This is now a monkey free zone.'
|
101
|
+
|
102
|
+
|
103
|
+
The following methods are provided:
|
104
|
+
|
105
|
+
* render_error(exception, errship3_scope = false) # Render the 500 page
|
106
|
+
* render_404_error(exception = nil, errship3_scope = false) # Render the 404 page
|
107
|
+
* flashback(error_message) # Set the flash and redirect back (RedirectBackError-safe)
|
108
|
+
|
109
|
+
If Airbrake is installed, every rescuer will report the exception, except for 404.
|
110
|
+
|
111
|
+
== Changelog
|
112
|
+
|
113
|
+
2.2.0
|
114
|
+
- Preserve correct status codes by default (Rescuers no longer force a 200 status)
|
115
|
+
|
116
|
+
2.1.3
|
117
|
+
- Conditionally loading rescuers to check for specific loading ORM
|
118
|
+
|
119
|
+
2.1.2
|
120
|
+
- Remove explicit Rake version dependency for 1.8.7 compatibility
|
121
|
+
|
122
|
+
2.1.1
|
123
|
+
- Gemspec update
|
124
|
+
|
125
|
+
2.1.0
|
126
|
+
- Removes unnecessary dependency on HAML (using ERB instead)
|
127
|
+
|
128
|
+
2.0.1
|
129
|
+
- Added tests for ActiveRecord, Mongoid and MongoMapper rescuers
|
130
|
+
- Fixed Mongoid module
|
131
|
+
|
132
|
+
2.0.0
|
133
|
+
- Breaks out ORM error handling into submodules. Not backwards compatible.
|
134
|
+
|
135
|
+
1.1.0
|
136
|
+
- Adds option to specify a custom errship3_scope to use with I18n, allowing each
|
137
|
+
rescuer to customize the messages displayed.
|
138
|
+
|
139
|
+
1.0.0
|
140
|
+
- Upgrade to Rails 3.1 to share error page assets between applications on the asset pipeline.
|
141
|
+
- Supports Airbrake as well as HoptoadNotifier
|
142
|
+
- Errors are rendered directly into your layout
|
143
|
+
- i18n support
|
144
|
+
- No default styles - blends seamlessly into its host layout.
|
145
|
+
|
146
|
+
== Contributing to errship3
|
147
|
+
|
148
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
149
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
150
|
+
* Fork the project
|
151
|
+
* Start a feature/bugfix branch
|
152
|
+
* Commit and push until you are happy with your contribution
|
153
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
154
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
155
|
+
|
156
|
+
== Copyright
|
157
|
+
|
158
|
+
Copyright (c) 2011 Logan Koester. See LICENSE.txt for
|
159
|
+
further details.
|
160
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require_tree .
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% content_for :head do %>
|
2
|
+
<%= stylesheet_link_tag 'errship3', :media => 'screen, projection' %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<div class='errship3'>
|
6
|
+
<h1 class='error_code'><%= status_code %></h1>
|
7
|
+
<% if errship3_scope %>
|
8
|
+
<h2><%= t "errship3.#{status_code}.#{errship3_scope}.title" %></h2>
|
9
|
+
<p><%= t "errship3.#{status_code}.#{errship3_scope}.description" %></p>
|
10
|
+
<% else %>
|
11
|
+
<h2><%= t "errship3.#{status_code}.title" %></h2>
|
12
|
+
<p><%= t "errship3.#{status_code}.description" %></p>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
if defined?(Rails::Application)
|
2
|
+
Rails.application.routes.draw do
|
3
|
+
# Unrecoverable error
|
4
|
+
match '/error' => "application#errship3_standard", :as => :error
|
5
|
+
match '/not_found' => "application#render_404_error", :as => 'not_found'
|
6
|
+
|
7
|
+
# Rails currently (until 3.1) ignores rescue_from ActionController::RoutingError, so render 404 manually
|
8
|
+
match '*address' => 'application#render_404_error' unless Rails.application.config.consider_all_requests_local
|
9
|
+
end
|
10
|
+
end
|
data/lib/errship3.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rescuers/active_record' if defined?(::ActiveRecord)
|
2
|
+
require 'rescuers/mongoid' if defined?(::Mongoid)
|
3
|
+
require 'rescuers/mongo_mapper' if defined?(::MongoMapper)
|
4
|
+
|
5
|
+
module Errship3
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
paths['app/routes'] = 'config/routes.rb'
|
8
|
+
paths['app/views'] << 'app/views'
|
9
|
+
paths['config/locales'] << 'config/locales'
|
10
|
+
end
|
11
|
+
|
12
|
+
mattr_accessor :status_code_success
|
13
|
+
@@status_code_success = true
|
14
|
+
|
15
|
+
module Rescuers
|
16
|
+
def self.included(base)
|
17
|
+
unless Rails.application.config.consider_all_requests_local
|
18
|
+
base.rescue_from ActionController::RoutingError, :with => :render_404_error
|
19
|
+
base.rescue_from ActionController::UnknownController, :with => :render_404_error
|
20
|
+
base.rescue_from ::AbstractController::ActionNotFound, :with => :render_404_error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_error(exception, errship3_scope = false)
|
25
|
+
airbrake_class.send(:notify, exception) if airbrake_class
|
26
|
+
render :template => '/errship3/standard', :locals => {
|
27
|
+
:status_code => 500, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 500)
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_404_error(exception = nil, errship3_scope = false)
|
31
|
+
render :template => '/errship3/standard', :locals => {
|
32
|
+
:status_code => 404, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 404)
|
33
|
+
end
|
34
|
+
|
35
|
+
# A blank page with just the layout and flash message, which can be redirected to when
|
36
|
+
# all else fails.
|
37
|
+
def errship3_standard(errship3_scope = false)
|
38
|
+
flash[:error] ||= 'An unknown error has occurred, or you have reached this page by mistake.'
|
39
|
+
render :template => '/errship3/standard', :locals => {
|
40
|
+
:status_code => 500, :errship3_scope => errship3_scope }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Set the error flash and attempt to redirect back. If RedirectBackError is raised,
|
44
|
+
# redirect to error_path instead.
|
45
|
+
def flashback(error_message, exception = nil)
|
46
|
+
airbrake_class.send(:notify, exception) if airbrake_class
|
47
|
+
flash[:error] = error_message
|
48
|
+
begin
|
49
|
+
redirect_to :back
|
50
|
+
rescue ActionController::RedirectBackError
|
51
|
+
redirect_to error_path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def airbrake_class
|
57
|
+
return Airbrake if defined?(Airbrake)
|
58
|
+
return HoptoadNotifier if defined?(HoptoadNotifier)
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% content_for :head do %>
|
2
|
+
<%= stylesheet_link_tag 'errship3', :media => 'screen, projection' %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<div class='errship3'>
|
6
|
+
<h1 class='error_code alert'><%= status_code %></h1>
|
7
|
+
<% if errship3_scope %>
|
8
|
+
<h2><%= t "errship3.#{status_code}.#{errship3_scope}.title" %></h2>
|
9
|
+
<p><%= t "errship3.#{status_code}.#{errship3_scope}.description" %></p>
|
10
|
+
<% else %>
|
11
|
+
<h2><%= t "errship3.#{status_code}.title" %></h2>
|
12
|
+
<p><%= t "errship3.#{status_code}.description" %></p>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module Errship3
|
3
|
+
class ViewGenerator < Rails::Generators::Base
|
4
|
+
desc "Generator Your View To Customize"
|
5
|
+
class_option :my_opt, :type => :boolean, :default => false, :desc => "My Option"
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
copy_file '../templates/standard.html.erb',
|
13
|
+
'app/views/errship3/standard.html.erb'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errship3-bootstrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Irfan Rizvi
|
9
|
+
- Nurul Ferdous
|
10
|
+
- Logan Koester
|
11
|
+
- Matthew Wilson
|
12
|
+
- David Czarnecki
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: rake
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
type: :development
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: shoulda
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.0.0
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: jeweler
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.6.0
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.6.0
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rails
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.2.9
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.2.9
|
98
|
+
description: Errship3 is a Rails 3.2 engine for rendering error pages inside your
|
99
|
+
layout. It supports i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.
|
100
|
+
email:
|
101
|
+
- irfanonrails@gmail.com
|
102
|
+
- nurul@ferdo.us
|
103
|
+
- lkoester@agoragames.com
|
104
|
+
- mwilson@agoragames.com
|
105
|
+
- dczarnecki@agoragames.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files:
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
files:
|
112
|
+
- app/assets/javascripts/application.js
|
113
|
+
- app/assets/stylesheets/errship3.css
|
114
|
+
- app/views/errship3/standard.html.erb
|
115
|
+
- config/locales/en.yml
|
116
|
+
- config/routes.rb
|
117
|
+
- lib/errship3.rb
|
118
|
+
- lib/generators/errship3/templates/standard.html.erb
|
119
|
+
- lib/generators/errship3/view_generator.rb
|
120
|
+
- lib/rescuers/active_record.rb
|
121
|
+
- lib/rescuers/mongo_mapper.rb
|
122
|
+
- lib/rescuers/mongoid.rb
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.rdoc
|
125
|
+
homepage: https://github.com/dynamicguy/errship3
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.8.24
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Errship3 is a Rails 3.2 engine for rendering error pages inside your layout.
|
150
|
+
test_files: []
|