goalie 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ ## Goalie
2
+
3
+ Goalie is a flexible dynamic error response renderer for Rails built
4
+ on Rack and Rails Engines. It provides the same default error pages as
5
+ Rails, but allows you to easily customize them with *dynamic*
6
+ content. This means you can use your application layout, have
7
+ different error pages for different subdomains, and do all sorts nice
8
+ things.
9
+
10
+ ## Installation
11
+
12
+ WARNING: at this point, Goalie is highly experimental and should not
13
+ be used in production!! Everything can and probably will change before
14
+ it is ready for production. Install it only if you want to play with
15
+ and/or contribute to it.
16
+
17
+ gem install goalie
18
+
19
+ After you install it and add it to your `Gemfile`, you have to require
20
+ it together with Rails' frameworks at the top of your
21
+ `config/application.rb` file:
22
+
23
+ require 'goalie/rails'
24
+
25
+ This will remove Rails' default exception renderer middleware
26
+ (`ShowExceptions`) and use Goalie's instead. Unless you have custom
27
+ static pages in your `public` directory (which we plan to support
28
+ later), this will be a drop-in replacement.
29
+
30
+ ## Customization
31
+
32
+ ### Controllers
33
+
34
+ The public (production) rescuing of errors is done by the
35
+ `PublicErrorsController` found in Goalie's `app/controllers`
36
+ directory. If you create a controller with the same name, it will
37
+ automatically be used instead of Goalie's. All it needs to do is
38
+ support the following actions:
39
+
40
+ * `internal_server_error`
41
+ * `not_found`
42
+ * `unprocessable_entity`
43
+ * `conflict`
44
+ * `method_not_allowed`
45
+ * `not_implemented`
46
+
47
+ If you don't actually need a separate action for each of these errors,
48
+ you can redirect them to others, for example, with:
49
+
50
+ def unprocessable_entity
51
+ render :action => 'internal_server_error'
52
+ end
53
+
54
+ ### Views
55
+
56
+ You can also customize only the views and use Goalie's default
57
+ controller. All you need is to have inside `app/views/public_errors`
58
+ views with the same names as the actions listed above. Besides the
59
+ standard stuff that Rails makes available to views, you will also have
60
+ access to the following instance variables:
61
+
62
+ * `@request`
63
+ * `@exception`
64
+ * `@application_trace`
65
+ * `@framework_trace`
66
+ * `@full_trace`
67
+
68
+ Be VERY careful when using this in production, as you could expose
69
+ sensitive information inside the request and exception. Generally, you
70
+ probably shouldn't use these variables at all. The only place it makes
71
+ sense is to have a more detailed error screen for admins or other
72
+ high-level users.
73
+
74
+ ## Credit
75
+
76
+ Goalie copies a lot of code and ideas from:
77
+ * Rails' `ShowExceptions` middleware
78
+ * Rails' default error views
79
+ * Rails' exception_notification plugin
80
+
81
+ Which are mostly the work of [Joshua Peek](http://joshpeek.com), with
82
+ help from various contributors. We're highly indebted to them and
83
+ thank them a lot for their work.
84
+
85
+ ## Contributions
86
+
87
+ Any form of feedback, patches, issues, and documentation are highly
88
+ appreciated.
89
+
90
+ ## License
91
+
92
+ MIT license. Copyright 2010 [Helder Ribeiro](http://helderribeiro.net).
93
+
@@ -1,5 +1,4 @@
1
1
  class LocalErrorsController < ActionController::Base
2
- self.append_view_path "#{File.dirname(__FILE__)}/../views"
3
2
 
4
3
  before_filter :set_error_instance_variables
5
4
 
@@ -1,23 +1,32 @@
1
1
  class PublicErrorsController < ActionController::Base
2
- self.append_view_path "#{File.dirname(__FILE__)}/../views"
3
2
 
4
- def internal_server_error
3
+ # 403
4
+ def forbidden
5
5
  end
6
6
 
7
+ # 404
7
8
  def not_found
8
9
  end
9
10
 
10
- def unprocessable_entity
11
+ # 405
12
+ def method_not_allowed
13
+ render :action => 'internal_server_error'
11
14
  end
12
15
 
16
+ # 409
13
17
  def conflict
14
18
  render :action => 'internal_server_error'
15
19
  end
16
20
 
17
- def method_not_allowed
18
- render :action => 'internal_server_error'
21
+ # 422
22
+ def unprocessable_entity
23
+ end
24
+
25
+ # 500
26
+ def internal_server_error
19
27
  end
20
28
 
29
+ # 501
21
30
  def not_implemented
22
31
  render :action => 'internal_server_error'
23
32
  end
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>You don't have permission to see this content (403)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <div class="dialog">
21
+ <h1>You don't have permission to see this content.</h1>
22
+ <p>You may need to acquire permission from the administrator first.</p>
23
+ </div>
24
+ </body>
25
+ </html>
@@ -17,7 +17,6 @@
17
17
  </head>
18
18
 
19
19
  <body>
20
- <!-- This file lives in public/500.html -->
21
20
  <div class="dialog">
22
21
  <h1>We're sorry, but something went wrong.</h1>
23
22
  <p>We've been notified about this issue and we'll take a look at it shortly.</p>
@@ -17,7 +17,6 @@
17
17
  </head>
18
18
 
19
19
  <body>
20
- <!-- This file lives in public/404.html -->
21
20
  <div class="dialog">
22
21
  <h1>The page you were looking for doesn't exist.</h1>
23
22
  <p>You may have mistyped the address or the page may have moved.</p>
@@ -17,7 +17,6 @@
17
17
  </head>
18
18
 
19
19
  <body>
20
- <!-- This file lives in public/422.html -->
21
20
  <div class="dialog">
22
21
  <h1>The change you wanted was rejected.</h1>
23
22
  <p>Maybe you tried to change something you didn't have access to.</p>
data/goalie.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{goalie}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Helder Ribeiro"]
12
+ s.date = %q{2010-08-11}
13
+ s.description = %q{Middleware to catch exceptions and Rails Engine to render them. Error-handling views and controllers can be easily overriden.}
14
+ s.email = %q{helder@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "app/controllers/local_errors_controller.rb",
23
+ "app/controllers/public_errors_controller.rb",
24
+ "app/views/layouts/local_errors.html.erb",
25
+ "app/views/local_errors/_request_and_response.html.erb",
26
+ "app/views/local_errors/_trace.html.erb",
27
+ "app/views/local_errors/diagnostics.html.erb",
28
+ "app/views/local_errors/missing_template.html.erb",
29
+ "app/views/local_errors/routing_error.html.erb",
30
+ "app/views/local_errors/template_error.html.erb",
31
+ "app/views/local_errors/unknown_action.html.erb",
32
+ "app/views/public_errors/forbidden.html",
33
+ "app/views/public_errors/internal_server_error.html",
34
+ "app/views/public_errors/not_found.html",
35
+ "app/views/public_errors/unprocessable_entity.html",
36
+ "goalie.gemspec",
37
+ "lib/goalie.rb",
38
+ "lib/goalie/exceptions.rb",
39
+ "lib/goalie/rails.rb",
40
+ "lib/goalie/version.rb",
41
+ "test/custom_error_pages_test.rb",
42
+ "todo.org"
43
+ ]
44
+ s.homepage = %q{http://github.com/obvio171/goalie}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.7}
48
+ s.summary = %q{Custom error pages for Rails}
49
+ s.test_files = [
50
+ "test/custom_error_pages_test.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ else
59
+ end
60
+ else
61
+ end
62
+ end
63
+
@@ -0,0 +1,6 @@
1
+ module Goalie
2
+
3
+ # 403 Forbidden
4
+ class ForbiddenAccess < StandardError; end # :nodoc
5
+
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Goalie
2
- VERSION = "0.0.0".freeze
2
+ VERSION = "0.0.1".freeze
3
3
  end
data/lib/goalie.rb CHANGED
@@ -11,25 +11,26 @@ module Goalie
11
11
  cattr_accessor :rescue_responses
12
12
  @@rescue_responses = Hash.new(:internal_server_error)
13
13
  @@rescue_responses.update({
14
- 'ActionController::RoutingError' => :not_found,
15
- 'AbstractController::ActionNotFound' => :not_found,
16
- 'ActiveRecord::RecordNotFound' => :not_found,
17
- 'ActiveRecord::StaleObjectError' => :conflict,
18
- 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
19
- 'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
20
- 'ActionController::MethodNotAllowed' => :method_not_allowed,
21
- 'ActionController::NotImplemented' => :not_implemented,
22
- 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
23
- })
14
+ 'ActionController::RoutingError' => :not_found,
15
+ 'AbstractController::ActionNotFound' => :not_found,
16
+ 'ActiveRecord::RecordNotFound' => :not_found,
17
+ 'ActiveRecord::StaleObjectError' => :conflict,
18
+ 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
19
+ 'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
20
+ 'ActionController::MethodNotAllowed' => :method_not_allowed,
21
+ 'ActionController::NotImplemented' => :not_implemented,
22
+ 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
23
+ 'Goalie::Forbidden' => :forbidden
24
+ })
24
25
 
25
26
  FAILSAFE_RESPONSE = [
26
- 500,
27
- {'Content-Type' => 'text/html'},
28
- ["<html><body><h1>500 Internal Server Error</h1>" <<
29
- "If you are the administrator of this website, then please read " <<
30
- "this web application's log file and/or the web server's log " <<
31
- "file to find out what went wrong.</body></html>"]
32
- ]
27
+ 500,
28
+ {'Content-Type' => 'text/html'},
29
+ ["<html><body><h1>500 Internal Server Error</h1>" <<
30
+ "If you are the administrator of this website, then please read " <<
31
+ "this web application's log file and/or the web server's log " <<
32
+ "file to find out what went wrong.</body></html>"]
33
+ ]
33
34
 
34
35
  def initialize(app, consider_all_requests_local = false)
35
36
  @app = app
@@ -77,11 +78,11 @@ module Goalie
77
78
  # controller handle different exception classes however it wants
78
79
  rescue_actions = Hash.new('diagnostics')
79
80
  rescue_actions.update({
80
- 'ActionView::MissingTemplate' => 'missing_template',
81
- 'ActionController::RoutingError' => 'routing_error',
82
- 'AbstractController::ActionNotFound' => 'unknown_action',
83
- 'ActionView::Template::Error' => 'template_error'
84
- })
81
+ 'ActionView::MissingTemplate' => 'missing_template',
82
+ 'ActionController::RoutingError' => 'routing_error',
83
+ 'AbstractController::ActionNotFound' => 'unknown_action',
84
+ 'ActionView::Template::Error' => 'template_error'
85
+ })
85
86
 
86
87
  error_params = {
87
88
  :request => request, :exception => exception,
data/todo.org CHANGED
@@ -1,8 +0,0 @@
1
-
2
- * Make views overridable from inside app
3
- * Make controllers overridable from inside app
4
- * Give proper credit to author of Rails' ShowExceptions
5
- * Give proper credit ao author of Rails' exception_notification
6
- * Give proper credit to Rails' default error pages that were copied
7
- * Turn into a gem
8
- * Create Railtie
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goalie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Helder Ribeiro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 -03:00
18
+ date: 2010-08-11 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -26,10 +26,10 @@ executables: []
26
26
  extensions: []
27
27
 
28
28
  extra_rdoc_files:
29
- - README
29
+ - README.md
30
30
  files:
31
31
  - MIT-LICENSE
32
- - README
32
+ - README.md
33
33
  - Rakefile
34
34
  - app/controllers/local_errors_controller.rb
35
35
  - app/controllers/public_errors_controller.rb
@@ -41,10 +41,13 @@ files:
41
41
  - app/views/local_errors/routing_error.html.erb
42
42
  - app/views/local_errors/template_error.html.erb
43
43
  - app/views/local_errors/unknown_action.html.erb
44
+ - app/views/public_errors/forbidden.html
44
45
  - app/views/public_errors/internal_server_error.html
45
46
  - app/views/public_errors/not_found.html
46
47
  - app/views/public_errors/unprocessable_entity.html
48
+ - goalie.gemspec
47
49
  - lib/goalie.rb
50
+ - lib/goalie/exceptions.rb
48
51
  - lib/goalie/rails.rb
49
52
  - lib/goalie/version.rb
50
53
  - test/custom_error_pages_test.rb
data/README DELETED
File without changes