exceptionally_beautiful 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a478d516a8c878e7d74548e35c8af2983db8c4a6
4
- data.tar.gz: 991e4c83503493a7c3c2902f7018b3f7fbd5eec9
3
+ metadata.gz: 6a36e540a4184161fb1862b7c35dbfe827a99537
4
+ data.tar.gz: 7388c72aacc54e8d45f8ab822626ec45c3e8359d
5
5
  SHA512:
6
- metadata.gz: 36e5d8da49a8fb778952c8741275e3417caf522839024281adcd738449c82f7af884f56022cb549ccd060149e3399505ec183e4b652309acaa38756a9b4f37a5
7
- data.tar.gz: 1b410e26bfddb8fd36b6a4137932218d88617945c2c48a094143cd45a77e13868b74fc81faf12054ad5557bd8c5e46a5a3403c977637607005e6b6c907b4f60e
6
+ metadata.gz: f6bf154bd9f2406d253105f5d3a44f39c4eca770be8db54c29fa8eebbd7107790a6b9e41f80cfe2e0603c24e4fcac4698d8180984565e626479643762a431e7b
7
+ data.tar.gz: cdc0ba7b4a29151887479f8e264d842ef7fd98bcf3a37c47d6ac35f2f06511fdc2bba17a2e09ce0cf0bd8fb9abbf587c46775972c2fb09bc371fc45037bac5be
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.2 (2015-02-25)
4
+
5
+ * Specify error codes the gem will handle via `config.errors`.
6
+ * Rake task for caching error pages in your app's public folder (see README for more information).
7
+ * Capistrano integration (see README for more information).
8
+
9
+ ## 0.1.1 (2015-02-10)
10
+
11
+ Removed beta restrictions from Rails dependency.
12
+
3
13
  ## 0.1.0 (2015-01-22)
4
14
 
5
15
  This release breaks the previous I18n translation file format. See the README for information on how the translation file should be setup now.
data/README.md CHANGED
@@ -24,7 +24,7 @@ The generator will:
24
24
 
25
25
  ## What You Get
26
26
 
27
- Exceptionally Beautiful will handle any three-digit status code you throw at it. It comes with translation data for the following common errors:
27
+ Exceptionally Beautiful can handle any three-digit status code you throw at it. It comes with translation data for the following common errors:
28
28
 
29
29
  | Code | Error |
30
30
  |------|:---------------------:|
@@ -34,23 +34,24 @@ Exceptionally Beautiful will handle any three-digit status code you throw at it.
34
34
  | 500 | Internal Server Error |
35
35
  | 502 | Bad Gateway |
36
36
 
37
- Any status code that is either unrecognized or missing translation data will fall back to default messaging.
38
-
39
37
  ## Customizing
40
38
 
41
- If the default controller, action, and/or layout don't suit your fancy, you can override any of them in the initializer provided by the generator:
39
+ If the default errors, controller, action, and/or layout don't suit your fancy, you can override any of them in the initializer provided by the generator:
42
40
 
43
41
  ``` ruby
44
42
  ExceptionallyBeautiful.setup do |config|
43
+ config.errors = [403, 404, 422, 500, 502]
45
44
  config.layout = 'errors'
46
45
  config.controller = 'exceptionally_beautiful/errors'
47
46
  config.action = 'show'
48
47
  end
49
48
  ```
50
49
 
50
+ **Important:** If you want Exceptionally Beautiful to handle an error code other than the defaults specified, it must be added to `config.errors`.
51
+
51
52
  ### Error Messages
52
53
 
53
- You can customize and add new errors to the translation file copied over by the initializer (`config/locales/exceptionally_beautiful.en.yml`).
54
+ You can customize and add new errors to the translation file copied over by the initializer (`config/locales/exceptionally_beautiful.en.yml`). Error codes missing translation data will fall back to default messaging.
54
55
 
55
56
  #### I18n Gotcha
56
57
 
@@ -83,7 +84,7 @@ The `message` for each error can be formatted using Markdown. e.g.
83
84
 
84
85
  ## Usage With `rescue_from`
85
86
 
86
- If you're using Rails' `rescue_from` functionality, you can still use Exceptionally Beautiful:
87
+ Using Rails' `rescue_from` in your controllers? You can use Exceptionally Beautiful's error handler there too:
87
88
 
88
89
  ``` ruby
89
90
  class ApplicationController < ActionController::Base
@@ -95,6 +96,28 @@ class ApplicationController < ActionController::Base
95
96
  end
96
97
  ```
97
98
 
99
+ ## Rake Task
100
+
101
+ This library comes with a Rake task that caches your beautiful error pages as static HTML files in your application's public folder.
102
+
103
+ ``` bash
104
+ bundle exec rake exceptionally_beautiful:cache
105
+ ```
106
+
107
+ ## Capistrano Integration
108
+
109
+ Want to cache your error pages as part of your deployment workflow? Use the included Capistrano 3 task:
110
+
111
+ ``` ruby
112
+ # In your Capfile
113
+ require 'exceptionally_beautiful/capistrano'
114
+
115
+ # In your config/deploy.rb
116
+ after 'deploy:compile_assets', 'exceptionally_beautiful:cache'
117
+ ```
118
+
119
+ By default, the `exceptionally_beautiful:cache` task is only run on servers with the `:app` role, however you can override that by setting the `:exceptionally_beautiful_roles` option.
120
+
98
121
  ## Inspiration & Alternatives
99
122
 
100
123
  This is by no means the first library to tackle this problem. Check out these other alternatives before deciding what to use.
@@ -0,0 +1,18 @@
1
+ namespace :exceptionally_beautiful do
2
+ desc "Cache all Exceptionally Beautiful error pages in your application's public folder"
3
+ task :cache do
4
+ on roles fetch(:exceptionally_beautiful_roles) do |host|
5
+ within release_path do
6
+ with :rails_env => fetch(:rails_env) do
7
+ execute :rake, 'exceptionally_beautiful:cache'
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ namespace :load do
15
+ task :defaults do
16
+ set :exceptionally_beautiful_roles, -> { :app }
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'capistrano/version'
2
+
3
+ if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
4
+ load File.expand_path('../capistrano/exceptionally_beautiful.rake', __FILE__)
5
+ else
6
+ fail LoadError
7
+ end
@@ -7,5 +7,9 @@ module ExceptionallyBeautiful
7
7
  initializer 'exceptionally_beautiful.update_exceptions_app' do |app|
8
8
  app.config.exceptions_app = app.routes
9
9
  end
10
+
11
+ rake_tasks do
12
+ load config.root.join('lib/exceptionally_beautiful/tasks/exceptionally_beautiful.rake')
13
+ end
10
14
  end
11
15
  end
@@ -1,3 +1,6 @@
1
+ require 'redcarpet'
2
+ require 'exceptionally_beautiful/html_renderer'
3
+
1
4
  module ExceptionallyBeautiful
2
5
  class MarkdownRenderer
3
6
  attr_reader :text
@@ -1,8 +1,11 @@
1
+ require 'exceptionally_beautiful/routing_constraint'
2
+
1
3
  module ActionDispatch::Routing
2
4
  class Mapper
3
5
  def exceptionally_beautiful_routes
4
6
  match '(errors)/:status', :to => "#{ExceptionallyBeautiful.controller}##{ExceptionallyBeautiful.action}",
5
- :constraints => { :status => /\d{3}/ }, :via => :all
7
+ :constraints => ExceptionallyBeautiful::RoutingConstraint.new, :via => :all,
8
+ :as => :exceptionally_beautiful_error
6
9
  end
7
10
  end
8
11
  end
@@ -0,0 +1,8 @@
1
+ module ExceptionallyBeautiful
2
+ class RoutingConstraint
3
+ def matches?(request)
4
+ status = request.env['action_dispatch.request.path_parameters'][:status]
5
+ !status.nil? && status.match(/\d{3}/) && ExceptionallyBeautiful.errors.include?(status.to_i)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ namespace :exceptionally_beautiful do
2
+ desc "Cache all Exceptionally Beautiful error pages in your application's public folder"
3
+ task :cache => :environment do
4
+ app = ActionDispatch::Integration::Session.new(Rails.application)
5
+ app.https!
6
+
7
+ ExceptionallyBeautiful.errors.each do |error_code|
8
+ app.get "/#{error_code}"
9
+
10
+ file_path = Rails.root.join('public')
11
+ file_name = "/#{error_code}.html"
12
+
13
+ File.open([file_path, file_name].join, 'w') { |f| f.write(app.response.body) }
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ExceptionallyBeautiful
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,9 +1,11 @@
1
1
  require 'exceptionally_beautiful/markdown_renderer'
2
- require 'exceptionally_beautiful/html_renderer'
3
2
  require 'exceptionally_beautiful/engine'
4
3
  require 'exceptionally_beautiful/routes'
5
4
 
6
5
  module ExceptionallyBeautiful
6
+ mattr_accessor :errors
7
+ self.errors = [403, 404, 422, 500, 502]
8
+
7
9
  mattr_accessor :controller
8
10
  self.controller = 'exceptionally_beautiful/errors'
9
11
 
@@ -1,4 +1,7 @@
1
1
  ExceptionallyBeautiful.setup do |config|
2
+ # The error codes to handle
3
+ # config.errors = [403, 404, 422, 500, 502]
4
+
2
5
  # The controller to use when rendering errors
3
6
  # config.controller = 'exceptionally_beautiful/errors'
4
7
 
@@ -12,7 +12,7 @@ feature 'something' do
12
12
  end
13
13
 
14
14
  describe 'default errors' do
15
- [403, 404, 422, 500, 502].each do |error_code|
15
+ ExceptionallyBeautiful.errors.each do |error_code|
16
16
  describe "#{error_code} error messaging" do
17
17
  let(:error) { ExceptionallyBeautiful::Error.new(error_code) }
18
18
  before { visit "/errors/#{error_code}" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptionally_beautiful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PJ Kelly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -222,10 +222,14 @@ files:
222
222
  - config/routes.rb
223
223
  - exceptionally_beautiful.gemspec
224
224
  - lib/exceptionally_beautiful.rb
225
+ - lib/exceptionally_beautiful/capistrano.rb
226
+ - lib/exceptionally_beautiful/capistrano/exceptionally_beautiful.rake
225
227
  - lib/exceptionally_beautiful/engine.rb
226
228
  - lib/exceptionally_beautiful/html_renderer.rb
227
229
  - lib/exceptionally_beautiful/markdown_renderer.rb
228
230
  - lib/exceptionally_beautiful/routes.rb
231
+ - lib/exceptionally_beautiful/routing_constraint.rb
232
+ - lib/exceptionally_beautiful/tasks/exceptionally_beautiful.rake
229
233
  - lib/exceptionally_beautiful/version.rb
230
234
  - lib/generators/exceptionally_beautiful/install_generator.rb
231
235
  - lib/generators/templates/exceptionally_beautiful.rb