whats-wrong 0.1.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: 91bd3b17e6ced0f331d647ab6e4af48ecb7d5e2b
4
+ data.tar.gz: 2118c26e584586184d3ec3e04a356cf22aab3a8b
5
+ SHA512:
6
+ metadata.gz: af8927c6e99a10fb2060520222b0ae3527b94615bf5951f8f9a4e24aab34aed53ef3f64e027c382425396445e320a3aec8ff3b1c7486193044821c020f5c3059
7
+ data.tar.gz: a895301b8ded48d4054b34c7e4c9070fb15a5496b0f170f7d35b60f470f88805c73d21c464344351860c131374e96220ab3a893e9bd4455b779b29073e6953af
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 bastengao
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.md ADDED
@@ -0,0 +1,30 @@
1
+ # Whats::Wrong
2
+ Overriding Rails default static error pages for your locale.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'whats-wrong'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+
14
+ #### Generate static pages for your locale
15
+
16
+ ```ruby
17
+ rails g whats_wrong:pages zh-CN
18
+ # Creating pages for zh-CN ...
19
+ # create public/404.zh-CN.html
20
+ # create public/422.zh-CN.html
21
+ # create public/500.zh-CN.html
22
+ ```
23
+
24
+ Supported locales: en, zh-CN.
25
+
26
+ ## Contributing
27
+ Contribution translations go here https://www.localeapp.com/projects/9397 .
28
+
29
+ ## License
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Whats::Wrong'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,11 @@
1
+ class WhatsWrong::ExceptionsController < ApplicationController
2
+
3
+ def show
4
+ exception = env['action_dispatch.exception']
5
+ path_info = request.path_info
6
+ status = path_info[1..-1].to_i
7
+ original_path = env["action_dispatch.original_path"]
8
+ render plain: "status: #{status}, origin_path: #{original_path}"
9
+ end
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ en:
2
+ pages:
3
+ '404':
4
+ description: You may have mistyped the address or the page may have moved.
5
+ header: The page you were looking for doesn't exist.
6
+ hint: If you are the application owner check the logs for more information.
7
+ title: The page you were looking for doesn't exist (404)
8
+ '422':
9
+ description: Maybe you tried to change something you didn't have access to.
10
+ header: The change you wanted was rejected.
11
+ hint: If you are the application owner check the logs for more information.
12
+ title: The change you wanted was rejected (422)
13
+ '500':
14
+ description:
15
+ header: We're sorry, but something went wrong.
16
+ hint: If you are the application owner check the logs for more information.
17
+ title: We're sorry, but something went wrong (500)
@@ -0,0 +1,17 @@
1
+ zh-CN:
2
+ pages:
3
+ '404':
4
+ description:
5
+ header:
6
+ hint:
7
+ title: 你访问的页面不存在
8
+ '422':
9
+ description:
10
+ header:
11
+ hint:
12
+ title:
13
+ '500':
14
+ description:
15
+ header:
16
+ hint:
17
+ title:
@@ -0,0 +1,14 @@
1
+ require 'rails/generators'
2
+
3
+ module WhatsWrong
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ def install
8
+ create_file("config/initializers/whats_wrong.rb", <<-RUBY)
9
+ WhatsWrong.enabled = true
10
+ RUBY
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ en:
2
+ pages:
3
+ '404':
4
+ title: The page you were looking for doesn't exist (404)
5
+ header: The page you were looking for doesn't exist.
6
+ description: You may have mistyped the address or the page may have moved.
7
+ hint: If you are the application owner check the logs for more information.
8
+ '422':
9
+ title: The change you wanted was rejected (422)
10
+ header: The change you wanted was rejected.
11
+ description: Maybe you tried to change something you didn't have access to.
12
+ hint: If you are the application owner check the logs for more information.
13
+ '500':
14
+ title: We're sorry, but something went wrong (500)
15
+ header: We're sorry, but something went wrong.
16
+ hint: If you are the application owner check the logs for more information.
@@ -0,0 +1,16 @@
1
+ zh-CN:
2
+ pages:
3
+ '404':
4
+ title: 你访问的页面不存在 (404)
5
+ header: 你访问的页面不存在。
6
+ description: 你可能把网址输错了或者该页面可能被移动到其他地方。
7
+ hint: 如果你是该网站的管理员,可以通过检查日志了解更多信息。
8
+ '422':
9
+ title: 你想要的改变被拒绝 (422)
10
+ header: 你想要的改变被拒绝。
11
+ description: 也许你没有权限改变的你想要改变的东西。
12
+ hint: 如果你是该网站的管理员,可以通过检查日志了解更多信息。
13
+ '500':
14
+ title: 抱歉,哪里出错了 (500)
15
+ header: 抱歉,哪里出错了。
16
+ hint: 如果你是该网站的管理员,可以通过检查日志了解更多信息。
@@ -0,0 +1,36 @@
1
+ require 'rails/generators'
2
+
3
+ module WhatsWrong
4
+ module Generators
5
+ class PagesGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def gen
9
+ locale = name
10
+ puts "Creating pages for #{locale} ..."
11
+
12
+ [404, 422, 500].each {|status| process(locale, status) }
13
+ rescue => e
14
+ puts e.message
15
+ end
16
+
17
+ protected
18
+ def process(locale, status)
19
+ # using: https://github.com/rails/rails/tree/master/railties/lib/rails/generators/rails/app/templates/public
20
+
21
+ @locales = locales(locale)['pages'][status.to_s]
22
+ template "#{status}.html", "public/#{status}.#{locale}.html"
23
+ end
24
+
25
+ def locales(locale)
26
+ locale_file = File.expand_path("../locales/#{locale}.yml", __FILE__)
27
+ if File.exist?(locale_file)
28
+ translations = YAML.load_file(locale_file)
29
+ translations[locale]
30
+ else
31
+ raise "The #{locale} is not supported currently. Contribute the translations if you can, visit https://www.localeapp.com/projects/9397 ."
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @locales['title'] %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1><%= @locales['header'] %></h1>
62
+ <p><%= @locales['description'] %></p>
63
+ </div>
64
+ <p><%= @locales['hint'] %></p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @locales['title'] %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1><%= @locales['header'] %></h1>
62
+ <p><%= @locales['description'] %></p>
63
+ </div>
64
+ <p><%= @locales['hint'] %></p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @locales['title'] %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1><%= @locales['header'] %></h1>
62
+ </div>
63
+ <p><%= @locales['hint'] %></p>
64
+ </div>
65
+ </body>
66
+ </html>
@@ -0,0 +1,4 @@
1
+ module WhatsWrong
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module WhatsWrong
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1 @@
1
+ require 'whats_wrong'
@@ -0,0 +1,13 @@
1
+ require 'whats-wrong/engine'
2
+
3
+ module WhatsWrong
4
+ mattr_reader :enabled
5
+
6
+ def self.enabled=(_enabled)
7
+ @@enabled = _enabled
8
+
9
+ if _enabled
10
+ Rails.application.config.exceptions_app = ->(env) { ExceptionsController.action(:show).call(env) }
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whats-wrong
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - bastengao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Overriding Rails default static error pages for your locale.
42
+ email:
43
+ - bastengao@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/controllers/whats_wrong/exceptions_controller.rb
52
+ - config/locales/en.yml
53
+ - config/locales/zh-CN.yml
54
+ - lib/generators/whats_wrong/install_generator.rb
55
+ - lib/generators/whats_wrong/locales/en.yml
56
+ - lib/generators/whats_wrong/locales/zh-CN.yml
57
+ - lib/generators/whats_wrong/pages_generator.rb
58
+ - lib/generators/whats_wrong/templates/404.html
59
+ - lib/generators/whats_wrong/templates/422.html
60
+ - lib/generators/whats_wrong/templates/500.html
61
+ - lib/whats-wrong.rb
62
+ - lib/whats-wrong/engine.rb
63
+ - lib/whats-wrong/version.rb
64
+ - lib/whats_wrong.rb
65
+ homepage: https://github.com/bastengao/whats-wrong
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.6.4
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Overriding Rails default static error pages for your locale.
89
+ test_files: []