errgent 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -18
- data/Rakefile +1 -1
- data/errgent.gemspec +2 -7
- data/lib/errgent.rb +3 -1
- data/lib/errgent/capistrano.rb +6 -5
- data/lib/errgent/capistrano/v2.rb +8 -0
- data/lib/errgent/capistrano/v3.rb +12 -0
- data/lib/errgent/engine.rb +3 -7
- data/lib/errgent/renderer.rb +28 -16
- data/lib/tasks/errgent.rake +4 -0
- data/test/errgent_renderer_test.rb +73 -28
- data/test/test_helper.rb +7 -3
- data/test/views/layouts/a_few_error_pages.html.erb +1 -0
- data/test/views/layouts/custom_helpers.html.erb +1 -0
- metadata +27 -23
- data/lib/errgent/task.rb +0 -40
- data/lib/errgent/version.rb +0 -3
- data/test/errgent_task_test.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21cda53c106227d17a3b92b51f13264df58354ed
|
4
|
+
data.tar.gz: 3c65683f9aa595db86c712c81e314ebbe128d3bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53833f13268f03a79b2854f84dcce20417228e5e3ac77996c25bc040118c6e3d5923980a9b0d80a2925fc51d16806c3d51c843dd5957bb14db358c5600939b8f
|
7
|
+
data.tar.gz: 2804360c95363c5e02c6da4026f17c963feb4c5174fa3b81269b39853def065e878027fb874cffb67a353ecb73e4cac0dd08ac4350c0e432550499ec8fb4f140
|
data/README.md
CHANGED
@@ -1,32 +1,65 @@
|
|
1
1
|
# Errgent
|
2
2
|
|
3
|
-
|
4
|
-
helpers or the other stuff you ever used in your templates. Out of the
|
5
|
-
has default error pages, but they're hardly maintained because if you
|
6
|
-
little change in one, you'll have to fix the others. With
|
7
|
-
changes and
|
3
|
+
Gently generate error pages using layout, your favorite markup language, basic
|
4
|
+
and url helpers or the other stuff you ever used in your templates. Out of the
|
5
|
+
box Rails has default error pages, but they're hardly maintained, because if you
|
6
|
+
do a little change in one, you'll have to fix the others. With `Errgent` you can
|
7
|
+
make changes and re-generate all pages at once.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'errgent'
|
13
|
+
```
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
15
|
-
|
16
|
-
`
|
17
|
-
|
18
|
-
|
19
|
-
template. You can create and customize your own rake task:
|
17
|
+
`Errgent` ships with rake task that you can run locally or on your server using
|
18
|
+
`Capistrano`. In order to generate pages simply run `rake errgent`. By default
|
19
|
+
`layouts/error_page` is used as a layout. But you can customize this behaviour
|
20
|
+
as many other things creating your own task in `lib/tasks/errgent.rake`:
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
```ruby
|
23
|
+
desc 'Generate error pages'
|
24
|
+
task errgent: :environment do
|
25
|
+
renderer = Errgent::Renderer.new(
|
26
|
+
codes: [403, 404, 422, 500], # error codes by default, @code variable is available in layout
|
27
|
+
vars: { name: 'value' }, # variable @name will be available in layout
|
28
|
+
layout: 'layouts/error_page', # where to find your layout by default
|
29
|
+
output: 'public/%s.html' # where to put generated pages by default, %s is the replacement for @code
|
30
|
+
)
|
31
|
+
|
32
|
+
# You can override or define new helpers:
|
33
|
+
renderer.helpers do
|
34
|
+
def current_user
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def logged_in?
|
39
|
+
false
|
25
40
|
end
|
41
|
+
end
|
42
|
+
|
43
|
+
renderer.render
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Capistrano
|
48
|
+
|
49
|
+
Since almost all applications use `Asset Pipeline`, the links to stylesheets,
|
50
|
+
js or images must be represented with digest in their names. It's barely possible
|
51
|
+
to do locally unless you generate assets locally either. That's why `Errgent`
|
52
|
+
ships with `Capistrano` task. Just put this to `deploy.rb` or `Capfile` (`~> 2.0`
|
53
|
+
and `~> 3.0` supported) and all the pages will be generated after
|
54
|
+
`assets:precompile` task on your server during deployment:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'errgent/capistrano'
|
58
|
+
```
|
26
59
|
|
27
|
-
|
28
|
-
|
29
|
-
|
60
|
+
In other words for development, generate pages locally see how it looks, fix it
|
61
|
+
if it needs. Then re-generate them on the server, because development version
|
62
|
+
isn't workable in production.
|
30
63
|
|
31
64
|
## License
|
32
65
|
|
data/Rakefile
CHANGED
data/errgent.gemspec
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'errgent/version'
|
5
|
-
|
6
1
|
Gem::Specification.new do |spec|
|
7
2
|
spec.name = 'errgent'
|
8
|
-
spec.version =
|
3
|
+
spec.version = '2.0.0'
|
9
4
|
spec.authors = 'Dmitry Vorotilin'
|
10
5
|
spec.email = 'd.vorotilin@gmail.com'
|
11
|
-
spec.description = 'Errgent generates error pages for your Rails application'
|
12
6
|
spec.summary = 'Error pages generator'
|
7
|
+
spec.description = 'Generate error pages for Rails applications'
|
13
8
|
spec.homepage = 'https://github.com/route/errgent'
|
14
9
|
spec.license = 'MIT'
|
15
10
|
|
data/lib/errgent.rb
CHANGED
data/lib/errgent/capistrano.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
Capistrano::
|
2
|
-
|
3
|
-
|
4
|
-
task :errgent do
|
5
|
-
run "cd #{latest_release} && RAILS_ENV=#{rails_env} bundle exec rake errgent"
|
1
|
+
if defined?(Capistrano::VERSION)
|
2
|
+
if Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
|
3
|
+
version = 3
|
6
4
|
end
|
7
5
|
end
|
6
|
+
|
7
|
+
version ||= 2
|
8
|
+
require_relative "capistrano/v#{version}"
|
data/lib/errgent/engine.rb
CHANGED
data/lib/errgent/renderer.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
class Errgent::Renderer
|
2
|
+
def initialize(options = {})
|
3
|
+
@vars = options[:vars] || {}
|
4
|
+
@codes = options[:codes] || [403, 404, 422, 500]
|
5
|
+
@layout = options[:layout] || 'layouts/error_page'
|
6
|
+
@output = options[:output] || 'public/%s.html'
|
7
|
+
end
|
8
|
+
|
9
|
+
def render
|
10
|
+
@codes.each do |code|
|
11
|
+
File.open(Rails.root.join(@output % code), 'w') do |io|
|
12
|
+
action_view.assign(@vars.merge(code: code))
|
13
|
+
io.write action_view.render(template: @layout)
|
12
14
|
end
|
13
15
|
end
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def helpers(&block)
|
19
|
+
action_view.class_eval(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def action_view
|
25
|
+
@action_view ||= begin
|
26
|
+
paths = ::ActionController::Base.view_paths
|
27
|
+
::ActionView::Base.new(paths).tap do |view|
|
28
|
+
view.class_eval do
|
29
|
+
include Rails.application.helpers
|
30
|
+
include Rails.application.routes.url_helpers
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
@@ -1,56 +1,101 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include ActiveSupport::Testing::Isolation
|
5
|
-
|
6
|
-
def setup
|
7
|
-
app.initialize!
|
8
|
-
@renderer = Errgent::Renderer.new
|
9
|
-
@renderer.action_view.lookup_context.view_paths = VIEW_PATH
|
10
|
-
end
|
3
|
+
class Errgent::RendererTest < ::MiniTest::Unit::TestCase
|
4
|
+
include ::ActiveSupport::Testing::Isolation
|
11
5
|
|
12
6
|
def test_renders_given_layout
|
13
|
-
|
7
|
+
@layout = 'layouts/given_layout'
|
8
|
+
@output = File.join(TMP_PATH, 'given_layout.html')
|
14
9
|
|
15
|
-
|
10
|
+
renderer.render
|
16
11
|
|
17
|
-
assert File.exists?(
|
18
|
-
assert_equal 'Hi, Dmitry!', File.read(
|
12
|
+
assert File.exists?(@output)
|
13
|
+
assert_equal 'Hi, Dmitry!', File.read(@output)
|
19
14
|
end
|
20
15
|
|
21
16
|
def test_assigns_vars
|
22
|
-
|
17
|
+
@vars = { object: 'you' }
|
18
|
+
@layout = 'layouts/assigns_vars'
|
19
|
+
@output = File.join(TMP_PATH, 'assigns_vars.html')
|
23
20
|
|
24
|
-
|
21
|
+
renderer.render
|
25
22
|
|
26
|
-
assert File.exists?(
|
27
|
-
assert_equal 'you', File.read(
|
23
|
+
assert File.exists?(@output)
|
24
|
+
assert_equal 'you', File.read(@output)
|
28
25
|
end
|
29
26
|
|
30
27
|
def test_url_helpers
|
31
|
-
|
28
|
+
@layout = 'layouts/url_helpers'
|
29
|
+
@output = File.join(TMP_PATH, 'url_helpers.html')
|
32
30
|
|
33
|
-
|
31
|
+
renderer.render
|
34
32
|
|
35
|
-
assert File.exists?(
|
36
|
-
assert_equal '/', File.read(
|
33
|
+
assert File.exists?(@output)
|
34
|
+
assert_equal '/', File.read(@output)
|
37
35
|
end
|
38
36
|
|
39
37
|
def test_app_helpers
|
40
|
-
|
38
|
+
@layout = 'layouts/app_helpers'
|
39
|
+
@output = File.join(TMP_PATH, 'app_helpers.html')
|
40
|
+
|
41
|
+
renderer.render
|
42
|
+
|
43
|
+
assert File.exists?(@output)
|
44
|
+
assert_equal 'hi_there!', File.read(@output)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_custom_helpers
|
48
|
+
@layout = 'layouts/custom_helpers'
|
49
|
+
@output = File.join(TMP_PATH, 'custom_helpers.html')
|
50
|
+
|
51
|
+
renderer.helpers do
|
52
|
+
def current_user
|
53
|
+
'Dmitry'
|
54
|
+
end
|
55
|
+
|
56
|
+
def role
|
57
|
+
'admin'
|
58
|
+
end
|
59
|
+
end
|
41
60
|
|
42
|
-
|
61
|
+
renderer.render
|
43
62
|
|
44
|
-
assert File.exists?(
|
45
|
-
assert_equal '
|
63
|
+
assert File.exists?(@output)
|
64
|
+
assert_equal 'Dmitry = admin', File.read(@output)
|
46
65
|
end
|
47
66
|
|
48
67
|
def test_partials
|
49
|
-
|
68
|
+
@layout = 'layouts/partials'
|
69
|
+
@output = File.join(TMP_PATH, 'partials.html')
|
70
|
+
|
71
|
+
renderer.render
|
72
|
+
|
73
|
+
assert File.exists?(@output)
|
74
|
+
assert_equal 'First', File.read(@output)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_a_few_error_pages
|
78
|
+
@codes = [404, 500]
|
79
|
+
@layout = 'layouts/a_few_error_pages'
|
80
|
+
@output = File.join(TMP_PATH, '%s.html')
|
81
|
+
|
82
|
+
renderer.render
|
83
|
+
|
84
|
+
assert File.exists?(@output % 404)
|
85
|
+
assert_equal '404', File.read(@output % 404)
|
86
|
+
|
87
|
+
assert File.exists?(@output % 500)
|
88
|
+
assert_equal '500', File.read(@output % 500)
|
89
|
+
end
|
50
90
|
|
51
|
-
|
91
|
+
private
|
52
92
|
|
53
|
-
|
54
|
-
|
93
|
+
def renderer
|
94
|
+
@renderer ||= begin
|
95
|
+
options = { codes: @codes || [404], layout: @layout, output: @output, vars: @vars }
|
96
|
+
Errgent::Renderer.new(options).tap do |renderer|
|
97
|
+
renderer.send(:action_view).lookup_context.view_paths = VIEW_PATH
|
98
|
+
end
|
99
|
+
end
|
55
100
|
end
|
56
101
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
1
3
|
require 'rails'
|
2
4
|
require 'action_view'
|
3
5
|
require 'action_controller'
|
4
6
|
require 'active_support/testing/isolation'
|
5
7
|
|
6
|
-
require 'minitest/autorun'
|
7
|
-
|
8
8
|
require 'errgent'
|
9
9
|
|
10
10
|
class MiniTest::Unit::TestCase
|
@@ -19,7 +19,7 @@ class MiniTest::Unit::TestCase
|
|
19
19
|
config.eager_load = false
|
20
20
|
|
21
21
|
routes {
|
22
|
-
root :
|
22
|
+
root to: 'home#index'
|
23
23
|
}
|
24
24
|
|
25
25
|
helpers_module = Module.new do
|
@@ -33,6 +33,10 @@ class MiniTest::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def setup
|
37
|
+
app.initialize!
|
38
|
+
end
|
39
|
+
|
36
40
|
def teardown
|
37
41
|
Dir[File.join(TMP_PATH, '*')].each { |f| File.delete(f) }
|
38
42
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @code %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= current_user %> = <%= role %>
|
metadata
CHANGED
@@ -1,106 +1,106 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errgent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Vorotilin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '4.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '4.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: tzinfo
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description: Generate error pages for Rails applications
|
98
98
|
email: d.vorotilin@gmail.com
|
99
99
|
executables: []
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
-
- .gitignore
|
103
|
+
- ".gitignore"
|
104
104
|
- Gemfile
|
105
105
|
- LICENSE.txt
|
106
106
|
- README.md
|
@@ -108,15 +108,17 @@ files:
|
|
108
108
|
- errgent.gemspec
|
109
109
|
- lib/errgent.rb
|
110
110
|
- lib/errgent/capistrano.rb
|
111
|
+
- lib/errgent/capistrano/v2.rb
|
112
|
+
- lib/errgent/capistrano/v3.rb
|
111
113
|
- lib/errgent/engine.rb
|
112
114
|
- lib/errgent/renderer.rb
|
113
|
-
- lib/errgent
|
114
|
-
- lib/errgent/version.rb
|
115
|
+
- lib/tasks/errgent.rake
|
115
116
|
- test/errgent_renderer_test.rb
|
116
|
-
- test/errgent_task_test.rb
|
117
117
|
- test/test_helper.rb
|
118
|
+
- test/views/layouts/a_few_error_pages.html.erb
|
118
119
|
- test/views/layouts/app_helpers.html.erb
|
119
120
|
- test/views/layouts/assigns_vars.html.erb
|
121
|
+
- test/views/layouts/custom_helpers.html.erb
|
120
122
|
- test/views/layouts/error_page.html.erb
|
121
123
|
- test/views/layouts/given_layout.html.erb
|
122
124
|
- test/views/layouts/partials.html.erb
|
@@ -132,28 +134,30 @@ require_paths:
|
|
132
134
|
- lib
|
133
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
136
|
requirements:
|
135
|
-
- -
|
137
|
+
- - ">="
|
136
138
|
- !ruby/object:Gem::Version
|
137
139
|
version: '0'
|
138
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
141
|
requirements:
|
140
|
-
- -
|
142
|
+
- - ">="
|
141
143
|
- !ruby/object:Gem::Version
|
142
144
|
version: '0'
|
143
145
|
requirements: []
|
144
146
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.2.2
|
146
148
|
signing_key:
|
147
149
|
specification_version: 4
|
148
150
|
summary: Error pages generator
|
149
151
|
test_files:
|
150
152
|
- test/errgent_renderer_test.rb
|
151
|
-
- test/errgent_task_test.rb
|
152
153
|
- test/test_helper.rb
|
154
|
+
- test/views/layouts/a_few_error_pages.html.erb
|
153
155
|
- test/views/layouts/app_helpers.html.erb
|
154
156
|
- test/views/layouts/assigns_vars.html.erb
|
157
|
+
- test/views/layouts/custom_helpers.html.erb
|
155
158
|
- test/views/layouts/error_page.html.erb
|
156
159
|
- test/views/layouts/given_layout.html.erb
|
157
160
|
- test/views/layouts/partials.html.erb
|
158
161
|
- test/views/layouts/url_helpers.html.erb
|
159
162
|
- test/views/part/_first.html.erb
|
163
|
+
has_rdoc:
|
data/lib/errgent/task.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/tasklib'
|
3
|
-
|
4
|
-
require 'errgent/renderer'
|
5
|
-
|
6
|
-
module Rake
|
7
|
-
class ErrgentTask < Rake::TaskLib
|
8
|
-
attr_reader :name, :renderer
|
9
|
-
attr_accessor :codes, :source, :destination
|
10
|
-
|
11
|
-
def initialize(name = :errgent)
|
12
|
-
@name = name
|
13
|
-
@renderer = Errgent::Renderer.new
|
14
|
-
|
15
|
-
@codes = [500, 403, 404, 422]
|
16
|
-
@source = File.join('layouts', 'error_page')
|
17
|
-
@destination = File.join('public', '%{code}.html')
|
18
|
-
|
19
|
-
yield self if block_given?
|
20
|
-
|
21
|
-
define
|
22
|
-
end
|
23
|
-
|
24
|
-
def define
|
25
|
-
desc 'Generates error pages'
|
26
|
-
task name => :environment do
|
27
|
-
generate_error_pages
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def generate_error_pages
|
34
|
-
codes.each do |code|
|
35
|
-
assigns = { :code => code }
|
36
|
-
renderer.render(source, destination % assigns, assigns)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/errgent/version.rb
DELETED
data/test/errgent_task_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ErrgentTaskTest < MiniTest::Unit::TestCase
|
4
|
-
include ActiveSupport::Testing::Isolation
|
5
|
-
|
6
|
-
def setup
|
7
|
-
app.initialize!
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_customize_settings
|
11
|
-
task = Rake::ErrgentTask.new do |t|
|
12
|
-
t.codes = 'codes'
|
13
|
-
t.source = 'source'
|
14
|
-
t.destination = 'destination'
|
15
|
-
end
|
16
|
-
|
17
|
-
assert_equal 'codes', task.codes
|
18
|
-
assert_equal 'source', task.source
|
19
|
-
assert_equal 'destination', task.destination
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_generate_error_pages
|
23
|
-
filename = File.join(TMP_PATH, 'error_page_%{code}.html')
|
24
|
-
task = Rake::ErrgentTask.new do |t|
|
25
|
-
t.codes = [500, 404]
|
26
|
-
t.destination = filename
|
27
|
-
t.renderer.action_view.lookup_context.view_paths = VIEW_PATH
|
28
|
-
end
|
29
|
-
|
30
|
-
task.send(:generate_error_pages)
|
31
|
-
|
32
|
-
_500, _404 = filename % { :code => 500 }, filename % { :code => 404 }
|
33
|
-
assert File.exists?(_500)
|
34
|
-
assert_equal '500 error!', File.read(_500)
|
35
|
-
assert File.exists?(_404)
|
36
|
-
assert_equal '404 error!', File.read(_404)
|
37
|
-
end
|
38
|
-
end
|