errgent 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11eb97f2e7cb08cb9d4306058e18795da984395d
4
+ data.tar.gz: 01c11ea3ae1a8ee271748ff28afc7d9203a71f7d
5
+ SHA512:
6
+ metadata.gz: 93a84710bb755fdf3b558f66fca991ff372e30fdacaeaf5bf4788a5e4f51d59091716047359801b335ae5b0318c78d9c35dff50f16e81762fd69cb6cf1bab60d
7
+ data.tar.gz: fa3e02d4d75db46fbaf5f6306f5375994185920319fee33980809696de133366c474993208f69933335871355181f1601708bdeffc90b835f61ba120868e11c9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dmitry Vorotilin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Errgent
2
+
3
+ Generates error pages using layout, your favorite markup language, basic and url
4
+ helpers or the other stuff you ever used in your templates. Out of the box Rails
5
+ has default error pages, but they're hardly maintained because if you do a
6
+ little change in one, you'll have to fix the others. With errgent you can make
7
+ changes and regenerate all pages at once.
8
+
9
+ ## Installation
10
+
11
+ gem 'errgent'
12
+
13
+ ## Usage
14
+
15
+ I'm pretty sure error pages should be lighter than application layout. Running
16
+ `rake errgent` will generate pages from `layouts/error_page` to public folder
17
+ with names as error codes(by default we generate `500.html`, `403.html`,
18
+ `404.html` and `422.html`). `@code` variable is available for you in the
19
+ template. You can create and customize your own rake task:
20
+
21
+ Rake::ErrgentTask.new do |t|
22
+ t.codes = [500, 404]
23
+ t.source = 'layouts/your_own'
24
+ t.destination = 'public/error_%{code}.html'
25
+ end
26
+
27
+ You can add generated pages to git index, and regenerate them on demand, or you
28
+ can add `require 'errgent/capistrano'` to `deploy.rb` and it will build pages on
29
+ server.
30
+
31
+ ## License
32
+
33
+ Errgent is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
data/errgent.gemspec ADDED
@@ -0,0 +1,27 @@
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
+ Gem::Specification.new do |spec|
7
+ spec.name = 'errgent'
8
+ spec.version = Errgent::VERSION
9
+ spec.authors = 'Dmitry Vorotilin'
10
+ spec.email = 'd.vorotilin@gmail.com'
11
+ spec.description = 'Errgent generates error pages for your Rails application'
12
+ spec.summary = 'Error pages generator'
13
+ spec.homepage = 'https://github.com/route/errgent'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^test/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'railties', '>= 3.0'
21
+ spec.add_runtime_dependency 'actionpack', '>= 3.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'minitest', '~> 4.0'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'tzinfo'
27
+ end
@@ -0,0 +1,7 @@
1
+ Capistrano::Configuration.instance.load do
2
+ after 'deploy:assets:precompile', 'errgent'
3
+
4
+ task :errgent do
5
+ run "cd #{latest_release} && RAILS_ENV=#{rails_env} bundle exec rake errgent"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'errgent/task'
2
+
3
+ module Errgent
4
+ class Engine < ::Rails::Engine
5
+ rake_tasks do
6
+ Rake::ErrgentTask.new
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Errgent
2
+ class Renderer
3
+ def action_view
4
+ @action_view ||= begin
5
+ paths = ActionController::Base.view_paths
6
+ ActionView::Base.new(paths).tap do |view|
7
+ view.class_eval do
8
+ include Rails.application.helpers
9
+ include Rails.application.routes.url_helpers
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def render(source, destination, assigns = {})
16
+ destination = Rails.root.join(destination)
17
+ File.open(destination, 'w') do |io|
18
+ action_view.assign(assigns)
19
+ io.write action_view.render(:template => source)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,3 @@
1
+ module Errgent
2
+ VERSION = '1.0.0'
3
+ end
data/lib/errgent.rb ADDED
@@ -0,0 +1 @@
1
+ require 'errgent/engine' if defined?(Rails)
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class ErrgentRendererTest < MiniTest::Unit::TestCase
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
11
+
12
+ def test_renders_given_layout
13
+ filename = File.join(TMP_PATH, 'given_layout.html')
14
+
15
+ @renderer.render('layouts/given_layout', filename)
16
+
17
+ assert File.exists?(filename)
18
+ assert_equal 'Hi, Dmitry!', File.read(filename)
19
+ end
20
+
21
+ def test_assigns_vars
22
+ filename = File.join(TMP_PATH, 'assigns_vars.html')
23
+
24
+ @renderer.render('layouts/assigns_vars', filename, { object: 'you' })
25
+
26
+ assert File.exists?(filename)
27
+ assert_equal 'you', File.read(filename)
28
+ end
29
+
30
+ def test_url_helpers
31
+ filename = File.join(TMP_PATH, 'url_helpers.html')
32
+
33
+ @renderer.render('layouts/url_helpers', filename)
34
+
35
+ assert File.exists?(filename)
36
+ assert_equal '/', File.read(filename)
37
+ end
38
+
39
+ def test_app_helpers
40
+ filename = File.join(TMP_PATH, 'app_helpers.html')
41
+
42
+ @renderer.render('layouts/app_helpers', filename)
43
+
44
+ assert File.exists?(filename)
45
+ assert_equal 'hi_there!', File.read(filename)
46
+ end
47
+
48
+ def test_partials
49
+ filename = File.join(TMP_PATH, 'partials.html')
50
+
51
+ @renderer.render('layouts/partials', filename)
52
+
53
+ assert File.exists?(filename)
54
+ assert_equal 'First', File.read(filename)
55
+ end
56
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,39 @@
1
+ require 'rails'
2
+ require 'action_view'
3
+ require 'action_controller'
4
+ require 'active_support/testing/isolation'
5
+
6
+ require 'minitest/autorun'
7
+
8
+ require 'errgent'
9
+
10
+ class MiniTest::Unit::TestCase
11
+ VIEW_PATH = File.expand_path('../views', __FILE__)
12
+ TMP_PATH = File.expand_path('../tmp', __FILE__)
13
+
14
+ def app
15
+ Class.new(Rails::Application).tap do |app|
16
+ app.configure do
17
+ config.active_support.deprecation = :notify
18
+ config.secret_token = 'a966a729a228e5d3edf00997e7b7eab7'
19
+ config.eager_load = false
20
+
21
+ routes {
22
+ root :to => 'home#index'
23
+ }
24
+
25
+ helpers_module = Module.new do
26
+ def hi_there
27
+ 'hi_there!'
28
+ end
29
+ end
30
+
31
+ helpers.send(:include, helpers_module)
32
+ end
33
+ end
34
+ end
35
+
36
+ def teardown
37
+ Dir[File.join(TMP_PATH, '*')].each { |f| File.delete(f) }
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ <%= hi_there %>
@@ -0,0 +1 @@
1
+ <%= @object %>
@@ -0,0 +1 @@
1
+ <%= @code %> error!
@@ -0,0 +1 @@
1
+ Hi, <%= 'Dmi' + 'try' %>!
@@ -0,0 +1 @@
1
+ <%= render 'part/first' %>
@@ -0,0 +1 @@
1
+ <%= root_path %>
@@ -0,0 +1 @@
1
+ First
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: errgent
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Vorotilin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tzinfo
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Errgent generates error pages for your Rails application
98
+ email: d.vorotilin@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - errgent.gemspec
109
+ - lib/errgent.rb
110
+ - lib/errgent/capistrano.rb
111
+ - lib/errgent/engine.rb
112
+ - lib/errgent/renderer.rb
113
+ - lib/errgent/task.rb
114
+ - lib/errgent/version.rb
115
+ - test/errgent_renderer_test.rb
116
+ - test/errgent_task_test.rb
117
+ - test/test_helper.rb
118
+ - test/views/layouts/app_helpers.html.erb
119
+ - test/views/layouts/assigns_vars.html.erb
120
+ - test/views/layouts/error_page.html.erb
121
+ - test/views/layouts/given_layout.html.erb
122
+ - test/views/layouts/partials.html.erb
123
+ - test/views/layouts/url_helpers.html.erb
124
+ - test/views/part/_first.html.erb
125
+ homepage: https://github.com/route/errgent
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.0.0
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Error pages generator
149
+ test_files:
150
+ - test/errgent_renderer_test.rb
151
+ - test/errgent_task_test.rb
152
+ - test/test_helper.rb
153
+ - test/views/layouts/app_helpers.html.erb
154
+ - test/views/layouts/assigns_vars.html.erb
155
+ - test/views/layouts/error_page.html.erb
156
+ - test/views/layouts/given_layout.html.erb
157
+ - test/views/layouts/partials.html.erb
158
+ - test/views/layouts/url_helpers.html.erb
159
+ - test/views/part/_first.html.erb