errship 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,117 @@
1
+ = => errship
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 Errship.
14
+
15
+ Errship 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
+ == Installation
23
+
24
+ Add this to your Gemfile
25
+ gem 'errship', '1.0.0'
26
+
27
+ Add this to your ApplicationController
28
+ class ApplicationController < ActionController::Base
29
+ include Errship::Rescuers
30
+
31
+ Errship is ready to go! To test it out in development, you'll need to set
32
+
33
+ config.consider_all_requests_local = false
34
+
35
+ in your config/environments/development.rb file. Just don't forget to change it back
36
+ when you want useful debugging output again instead!
37
+
38
+ Alternatively, simply point your browser to /error or /not_found to get a taste.
39
+
40
+ == I18n
41
+
42
+ If you want to edit the text that is rendered, add the following to your config/locales/*.yml
43
+
44
+ en:
45
+ errship:
46
+ '404':
47
+ title: 'This page does not exist.'
48
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
49
+ '500':
50
+ title: 'An error has occurred.'
51
+ description: 'This has been reported to our development team. Thank you!'
52
+
53
+ ...and so forth, for any error code you like.
54
+
55
+ == Custom Rescuers
56
+
57
+ If you want errship to rescue errors from your own custom exception class, you need
58
+ to add a custom rescuer in your ApplicationController, like so:
59
+
60
+ # Render the 404 page
61
+ rescue_from MyException::SomethingMissing, :with => :render_404_error
62
+
63
+ # Render the 500 page
64
+ rescue_from MyException::SomethingWentWrong, :with => :render_error
65
+
66
+ To customize the error for a particular controller or exception class, add a rescuer
67
+ like this one:
68
+
69
+ rescue_from ActiveRecord::RecordNotFound, :with => ->(e){ render_404_error e, 'monkeys' }
70
+
71
+ and then add your text for that scope to config/locales/*.yml
72
+
73
+ en:
74
+ errship:
75
+ '404':
76
+ title: 'This page does not exist.'
77
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
78
+ monkeys:
79
+ title: 'They must have escaped'
80
+ description: 'This is now a monkey free zone.'
81
+
82
+
83
+ The following methods are provided:
84
+
85
+ * render_error(exception, errship_scope = false) # Render the 500 page
86
+ * render_404_error(exception = nil, errship_scope = false) # Render the 404 page
87
+ * flashback(error_message) # Set the flash and redirect back (RedirectBackError-safe)
88
+
89
+ If Airbrake is installed, every rescuer will report the exception, except for 404.
90
+
91
+ == Changelog
92
+ 1.1.0
93
+ - Adds option to specify a custom errship_scope to use with I18n, allowing each
94
+ rescuer to customize the messages displayed.
95
+
96
+ 1.0.0
97
+ - Upgrade to Rails 3.1 to share error page assets between applications on the asset pipeline.
98
+ - Supports Airbrake as well as HoptoadNotifier
99
+ - Errors are rendered directly into your layout
100
+ - i18n support
101
+ - No default styles - blends seamlessly into its host layout.
102
+
103
+ == Contributing to errship
104
+
105
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
106
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
107
+ * Fork the project
108
+ * Start a feature/bugfix branch
109
+ * Commit and push until you are happy with your contribution
110
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
111
+ * 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.
112
+
113
+ == Copyright
114
+
115
+ Copyright (c) 2011 Logan Koester. See LICENSE.txt for
116
+ further details.
117
+
@@ -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,2 @@
1
+ .errship {
2
+ }
@@ -0,0 +1,11 @@
1
+ - content_for :head do
2
+ = stylesheet_link_tag 'errship', :media => 'screen, projection'
3
+
4
+ .errship
5
+ %h1.error_code #{status_code}
6
+ - if errship_scope
7
+ %h2= t "errship.#{status_code}.#{errship_scope}.title"
8
+ %p= t "errship.#{status_code}.#{errship_scope}.description"
9
+ - else
10
+ %h2= t "errship.#{status_code}.title"
11
+ %p= t "errship.#{status_code}.description"
@@ -0,0 +1,8 @@
1
+ en:
2
+ errship:
3
+ '404':
4
+ title: 'This page does not exist.'
5
+ description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
6
+ '500':
7
+ title: 'An error has occurred.'
8
+ description: 'This has been reported to our development team. Thank you!'
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#errship_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/errship.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'haml'
2
+
3
+ module Errship
4
+ class Engine < ::Rails::Engine
5
+ paths['app/routes'] = 'config/routes.rb'
6
+ paths['app/views'] << 'app/views'
7
+ paths['config/locales'] << 'config/locales'
8
+ end
9
+
10
+ module Rescuers
11
+ def self.included(base)
12
+ unless Rails.application.config.consider_all_requests_local
13
+ base.rescue_from Exception, :with => :render_error
14
+ base.rescue_from ActiveRecord::RecordNotFound, :with => :render_404_error
15
+ base.rescue_from ActionController::RoutingError, :with => :render_404_error
16
+ base.rescue_from ActionController::UnknownController, :with => :render_404_error
17
+ base.rescue_from ActionController::UnknownAction, :with => :render_404_error
18
+ end
19
+ end
20
+
21
+ def render_error(exception, errship_scope = false)
22
+ airbrake_class.send(:notify, exception) if airbrake_class
23
+ render :template => '/errship/standard', :locals => {
24
+ :status_code => 500, :errship_scope => errship_scope }
25
+ end
26
+
27
+ def render_404_error(exception = nil, errship_scope = false)
28
+ render :template => '/errship/standard', :locals => {
29
+ :status_code => 404, :errship_scope => errship_scope }
30
+ end
31
+
32
+ # A blank page with just the layout and flash message, which can be redirected to when
33
+ # all else fails.
34
+ def errship_standard(errship_scope = false)
35
+ flash[:error] ||= 'An unknown error has occurred, or you have reached this page by mistake.'
36
+ render :template => '/errship/standard', :locals => {
37
+ :status_code => 500, :errship_scope => errship_scope }
38
+ end
39
+
40
+ # Set the error flash and attempt to redirect back. If RedirectBackError is raised,
41
+ # redirect to error_path instead.
42
+ def flashback(error_message, exception = nil)
43
+ airbrake_class.send(:notify, exception) if airbrake_class
44
+ flash[:error] = error_message
45
+ begin
46
+ redirect_to :back
47
+ rescue ActionController::RedirectBackError
48
+ redirect_to error_path
49
+ end
50
+ end
51
+
52
+ private
53
+ def airbrake_class
54
+ return Airbrake if defined?(Airbrake)
55
+ return HoptoadNotifier if defined?(HoptoadNotifier)
56
+ return false
57
+ end
58
+
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: errship
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Logan Koester
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-01 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: haml
17
+ requirement: &25882600 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *25882600
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &25881980 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - =
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *25881980
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ requirement: &25881360 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *25881360
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &25880620 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *25880620
59
+ - !ruby/object:Gem::Dependency
60
+ name: jeweler
61
+ requirement: &25880080 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.6.0
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *25880080
70
+ - !ruby/object:Gem::Dependency
71
+ name: rcov
72
+ requirement: &25879560 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *25879560
81
+ description: Errship is a Rails 3.1 engine for rendering error pages inside your layout.
82
+ It supports i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.
83
+ email: lkoester@agoragames.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files:
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ files:
90
+ - app/assets/javascripts/application.js
91
+ - app/assets/stylesheets/errship.css
92
+ - app/views/errship/standard.html.haml
93
+ - config/locales/en.yml
94
+ - config/routes.rb
95
+ - lib/errship.rb
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ has_rdoc: true
99
+ homepage: http://github.com/logankoester/errship
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: 1469100541760002467
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.6.2
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Errship is a Rails 3.1 engine for rendering error pages inside your layout.
127
+ test_files: []