rambulance 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e93097596c103ed91bc9ab7bab5a731320278a9
4
- data.tar.gz: 8c00647c34dcef11d40880a653108b06783101eb
3
+ metadata.gz: 8cbab6ea7d38072ab9ddf4b8eaaa06fd46be2ee1
4
+ data.tar.gz: be1217d51c085bcc772d45deb9f64d3fdfd1415d
5
5
  SHA512:
6
- metadata.gz: b42c61e3fb53638c22b8988aca6da3c080474c2b8804b10512eec7b302d21ab22cb65142f189a73999530fc4d0439757adec198f57cf9882b8b2dd274e45cd83
7
- data.tar.gz: 930c7ed06d8dd0004ef566d80d8d076b69cc732013c2bf02caae649248ab63faadd10d110e9978d99921e808959bf7a134eb8bb3b09f98538ca6b3c1a214e99f
6
+ metadata.gz: caed478d2b08c895c525200c894d8d13ae623e1e0a9853702d719b36d845ce3eec3db92bee3bc0fdbaf4fafca40758c7f16ec3e18c525ff13af1826fbfa20846
7
+ data.tar.gz: f73c89f22c997e5adf807bf515b76221a0ef938e0f394add8da2a3cb7deb0a61fbf2556a35349f19ae25940b01859cc10a3fd50fa41f5054831cf16427d463b8
@@ -7,11 +7,12 @@ rvm:
7
7
  - 1.9.3
8
8
  - 2.0.0
9
9
  - 2.1
10
- - 2.2
10
+ - 2.2.2
11
11
  - ruby-head
12
12
  - jruby
13
13
  - jruby-head
14
14
  - rbx-2.4.1
15
+ - rbx-2.5.3
15
16
 
16
17
  gemfile:
17
18
  - gemfiles/rails_32.gemfile
@@ -28,7 +29,7 @@ matrix:
28
29
  gemfile: gemfiles/rails_edge.gemfile
29
30
  - rvm: 2.1
30
31
  gemfile: gemfiles/rails_edge.gemfile
31
- - rvm: 2.2
32
+ - rvm: 2.2.2
32
33
  gemfile: gemfiles/rails_32.gemfile
33
34
  - rvm: ruby-head
34
35
  gemfile: gemfiles/rails_32.gemfile
@@ -37,5 +38,7 @@ matrix:
37
38
  - rvm: jruby
38
39
  - rvm: jruby-head
39
40
  - rvm: rbx-2.4.1
41
+ - rvm: rbx-2.5.3
40
42
  - gemfile: gemfiles/rails_edge.gemfile
43
+ - gemfile: gemfiles/rails_32.gem
41
44
  fast_finish: true
data/README.md CHANGED
@@ -30,6 +30,13 @@ And then execute:
30
30
  $ rails g rambulance:install
31
31
  ```
32
32
 
33
+ or specify the template engine by:
34
+ ```
35
+ $ rails g rambulance:install -e slim
36
+ ```
37
+
38
+ Rambulance now support `erb`, `haml`, `slim` template engines, if you don't specify the `-e` option, erb will be used as default.
39
+
33
40
  Now you can start editing templates like `app/views/errors/not_found.html.erb`. Edit, run `rails server` and open [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found)!
34
41
 
35
42
  ## Setting Pairs of Exceptions and HTTP Statuses
@@ -96,8 +103,8 @@ It'll generate your own custom exceptions app. You can use whatever techniques y
96
103
 
97
104
  ## Supported Versions
98
105
 
99
- * Ruby 1.9.3, 2.0.0, 2.1.2, JRuby 1.7.11, Rubinius 2.2.6
100
- * Rails 3.2, 4.0, 4.1
106
+ * Ruby 1.9.3, 2.0.0, 2.1, 2.2, JRuby 1.7.19, JRuby head, Rubinius 2.4.1 and 2.5.3
107
+ * Rails 3.2, 4.0, 4.1, 4.2 and edge
101
108
 
102
109
  Rambulance doesn't work with Rails 3.1 and below since they don't provide any way to use a custom exceptions app.
103
110
 
@@ -111,4 +118,4 @@ Rambulance doesn't work with Rails 3.1 and below since they don't provide any wa
111
118
 
112
119
  ## License
113
120
 
114
- Copyright (c) 2014 Yuki Nishijima. See LICENSE.txt for further details.
121
+ Copyright (c) 2014-2015 Yuki Nishijima. See LICENSE.txt for further details.
@@ -5,5 +5,6 @@ source "https://rubygems.org"
5
5
  gem "activesupport", "~> 3.2.0"
6
6
  gem "actionpack", "~> 3.2.0"
7
7
  gem "railties", "~> 3.2.0"
8
+ gem 'jbuilder', '2.2.13'
8
9
 
9
10
  gemspec :path => "../"
@@ -6,12 +6,7 @@ module Rambulance
6
6
  class_option :template_engine,
7
7
  type: :string,
8
8
  aliases: '-e',
9
- desc: 'Template engine for the views. Available options are "erb" and "haml".'
10
-
11
- class_option :error_layout,
12
- type: :string,
13
- aliases: '-l',
14
- desc: 'Copies app/views/layout/application.html.erb to the specified layout name'
9
+ desc: 'Template engine for the views. Available options are "erb", "slim" and "haml".'
15
10
 
16
11
  def self.banner #:nodoc:
17
12
  <<-BANNER.chomp
@@ -29,17 +24,17 @@ BANNER
29
24
  copy_file "views/#{f}", "app/views/errors/#{f}"
30
25
  end
31
26
 
32
- filename_pattern = File.join(self.class.source_root, "views", "*.json.jbuilder")
33
- Dir.glob(filename_pattern).map {|f| File.basename f }.each do |f|
34
- copy_file "views/#{f}", "app/views/errors/#{f}"
27
+ if defined?(Jbuilder)
28
+ filename_pattern = File.join(self.class.source_root, "views", "*.json.jbuilder")
29
+ Dir.glob(filename_pattern).map {|f| File.basename f }.each do |f|
30
+ copy_file "views/#{f}", "app/views/errors/#{f}"
31
+ end
35
32
  end
36
33
  end
37
34
 
38
35
  def copy_layout #:nodoc:
39
- return if layout_name == "application"
40
-
41
- say "\n" "copying app/views/layouts/application.html.#{template_engine} to app/views/layouts/#{layout_name}.html.#{template_engine}:"
42
- copy_file Rails.root.join("app/views/layouts/application.html.#{template_engine}"), "app/views/layouts/#{layout_name}.html.#{template_engine}"
36
+ say "\ncopying app/views/layouts/application.html.#{template_engine} to app/views/layouts/error.html.#{template_engine}:"
37
+ copy_file Rails.root.join("app/views/layouts/application.html.#{template_engine}"), "app/views/layouts/error.html.#{template_engine}"
43
38
  end
44
39
 
45
40
  def copy_initializer #:nodoc:
@@ -53,10 +48,6 @@ BANNER
53
48
  options[:template_engine].try(:to_s).try(:downcase) || 'erb'
54
49
  end
55
50
 
56
- def layout_name
57
- options[:error_layout].try(:to_s).try(:downcase) || "application"
58
- end
59
-
60
51
  def longest_error_name_size
61
52
  ActionDispatch::ExceptionWrapper.rescue_responses.keys.sort_by(&:size).last.size
62
53
  end
@@ -22,9 +22,9 @@ Rambulance.setup do |config|
22
22
  }
23
23
 
24
24
  # The template name for the layout of the error pages. The default value is
25
- # 'application'. For exmaple, if this value is set to "error_page", Rambulance uses
25
+ # 'error'. For exmaple, if this value is set to "error_page", Rambulance uses
26
26
  # 'app/views/layout/error_page.html.erb' as a layout for all the error pages.
27
- config.layout_name = "<%= layout_name %>"
27
+ config.layout_name = "error"
28
28
 
29
29
  # The directry name to organize error page templates. The default value is
30
30
  # 'errors'. For exmaple, if this value is set to "error_pages", Rambulance
@@ -0,0 +1,8 @@
1
+ style
2
+ | div.dialog { color: #2E2F30; text-align: center; font-family: arial, sans-serif; margin: 0; width: 95%; max-width: 33em; margin: 4em auto; } div.dialog > div { border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #BBB; border-top: #B00100 solid 4px; border-top-left-radius: 9px; border-top-right-radius: 9px; background-color: white; padding: 7px 12% 0; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); } h1 { font-size: 100%; color: #730E15; line-height: 1.5em; margin: 10px 0; } div.dialog p { margin: 16px 0; } div.dialog > p { margin: 0 0 1em; padding: 1em; background-color: #F7F7F7; border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #999; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-color: #DADADA; color: #666; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); }
3
+ .dialog
4
+ div
5
+ h1
6
+ | Bad request
7
+ p
8
+ | The service received a incomplete request.
@@ -0,0 +1,8 @@
1
+ style
2
+ | div.dialog { color: #2E2F30; text-align: center; font-family: arial, sans-serif; margin: 0; width: 95%; max-width: 33em; margin: 4em auto; } div.dialog > div { border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #BBB; border-top: #B00100 solid 4px; border-top-left-radius: 9px; border-top-right-radius: 9px; background-color: white; padding: 7px 12% 0; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); } h1 { font-size: 100%; color: #730E15; line-height: 1.5em; margin: 10px 0; } div.dialog p { margin: 16px 0; } div.dialog > p { margin: 0 0 1em; padding: 1em; background-color: #F7F7F7; border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #999; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-color: #DADADA; color: #666; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); }
3
+ .dialog
4
+ div
5
+ h1
6
+ | Forbidden.
7
+ p
8
+ | You are not authorized to access this page.
@@ -0,0 +1,8 @@
1
+ style
2
+ | div.dialog { color: #2E2F30; text-align: center; font-family: arial, sans-serif; margin: 0; width: 95%; max-width: 33em; margin: 4em auto; } div.dialog > div { border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #BBB; border-top: #B00100 solid 4px; border-top-left-radius: 9px; border-top-right-radius: 9px; background-color: white; padding: 7px 12% 0; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); } h1 { font-size: 100%; color: #730E15; line-height: 1.5em; margin: 10px 0; } div.dialog p { margin: 16px 0; } div.dialog > p { margin: 0 0 1em; padding: 1em; background-color: #F7F7F7; border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #999; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-color: #DADADA; color: #666; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); }
3
+ .dialog
4
+ div
5
+ h1
6
+ | We're sorry, but something went wrong.
7
+ p
8
+ | If you are the application owner check the logs for more information.
@@ -0,0 +1,10 @@
1
+ style
2
+ | div.dialog { color: #2E2F30; text-align: center; font-family: arial, sans-serif; margin: 0; width: 95%; max-width: 33em; margin: 4em auto; } div.dialog > div { border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #BBB; border-top: #B00100 solid 4px; border-top-left-radius: 9px; border-top-right-radius: 9px; background-color: white; padding: 7px 12% 0; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); } h1 { font-size: 100%; color: #730E15; line-height: 1.5em; margin: 10px 0; } div.dialog p { margin: 16px 0; } div.dialog > p { margin: 0 0 1em; padding: 1em; background-color: #F7F7F7; border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #999; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-color: #DADADA; color: #666; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); }
3
+ .dialog
4
+ div
5
+ h1
6
+ | The page you were looking for doesn't exist.
7
+ p
8
+ | You may have mistyped the address or the page may have moved.
9
+ p
10
+ | If you are the application owner check the logs for more information.
@@ -0,0 +1,10 @@
1
+ style
2
+ | div.dialog { color: #2E2F30; text-align: center; font-family: arial, sans-serif; margin: 0; width: 95%; max-width: 33em; margin: 4em auto; } div.dialog > div { border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #BBB; border-top: #B00100 solid 4px; border-top-left-radius: 9px; border-top-right-radius: 9px; background-color: white; padding: 7px 12% 0; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); } h1 { font-size: 100%; color: #730E15; line-height: 1.5em; margin: 10px 0; } div.dialog p { margin: 16px 0; } div.dialog > p { margin: 0 0 1em; padding: 1em; background-color: #F7F7F7; border: 1px solid #CCC; border-right-color: #999; border-left-color: #999; border-bottom-color: #999; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-color: #DADADA; color: #666; box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17); }
3
+ .dialog
4
+ div
5
+ h1
6
+ | The change you wanted was rejected.
7
+ p
8
+ | Maybe you tried to change something you didn't have access to.
9
+ p
10
+ | If you are the application owner check the logs for more information.
@@ -10,6 +10,12 @@ module Rambulance
10
10
  class ExceptionsApp < ActionController::Base
11
11
  layout :layout_name
12
12
 
13
+ BAD_REQUEST_EXCEPTION = begin
14
+ ActionController::BadRequest
15
+ rescue NameError
16
+ TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
17
+ end
18
+
13
19
  def self.call(env)
14
20
  exception = env["action_dispatch.exception"]
15
21
  status_in_words = if exception
@@ -40,7 +46,7 @@ module Rambulance
40
46
  def process_action(*)
41
47
  begin
42
48
  request.GET
43
- rescue bad_request_exception
49
+ rescue BAD_REQUEST_EXCEPTION
44
50
  env["MALFORMED_QUERY_STRING"], env["QUERY_STRING"] = env["QUERY_STRING"], ""
45
51
  end
46
52
 
@@ -68,19 +74,13 @@ module Rambulance
68
74
  end
69
75
 
70
76
  def layout_name
71
- Rambulance.layout_name
77
+ request.format.json? ? false : Rambulance.layout_name
72
78
  end
73
79
 
74
80
  def controller_path
75
81
  Rambulance.view_path
76
82
  end
77
83
 
78
- def bad_request_exception
79
- ActionController::BadRequest
80
- rescue NameError
81
- TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
82
- end
83
-
84
84
  helper_method :status_in_words, :exception
85
85
  end
86
86
  end
@@ -1,25 +1,20 @@
1
1
  module Rambulance
2
2
  class Railtie < Rails::Railtie
3
- initializer "action_controller" do |app|
3
+ initializer 'rambulance' do |app|
4
4
  require "rambulance/exceptions_app"
5
- end
6
5
 
7
- initializer "activesupport.dependencies" do |app|
8
- begin
9
- ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
10
- app.config.exceptions_app = ->(env){ ::ExceptionsApp.call(env) }
11
- rescue NameError
12
- app.config.exceptions_app = ::Rambulance::ExceptionsApp
13
- end
14
- end
6
+ app.config.exceptions_app =
7
+ begin
8
+ ActiveSupport::Dependencies.load_missing_constant(Object, :ExceptionsApp)
9
+ ->(env){ ::ExceptionsApp.call(env) }
10
+ rescue NameError
11
+ ::Rambulance::ExceptionsApp
12
+ end
15
13
 
16
- initializer 'rambulance' do |app|
17
14
  ActiveSupport.on_load(:after_initialize) do
18
- if Rails.env.development?
19
- Rails.application.routes.append do
20
- mount app.config.exceptions_app, at: '/rambulance'
21
- end
22
- end
15
+ Rails.application.routes.append do
16
+ mount app.config.exceptions_app, at: '/rambulance'
17
+ end if Rails.env.development?
23
18
  end
24
19
  end
25
20
  end
@@ -1,3 +1,3 @@
1
1
  module Rambulance
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -1,4 +1,3 @@
1
- # require 'rails/all'
2
1
  require 'action_controller/railtie'
3
2
  require 'action_view/railtie'
4
3
  require 'jbuilder'
@@ -7,7 +7,19 @@ feature 'Error json response', if: !ENV["CUSTOM_EXCEPTIONS_APP"], type: :request
7
7
  end
8
8
 
9
9
  def get(path)
10
- super(path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")
10
+ without_layouts do
11
+ super(path, nil, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json")
12
+ end
13
+ end
14
+
15
+ def without_layouts
16
+ `mv spec/fake_app/app/views/layouts/application.html.erb .`
17
+ `mv spec/fake_app/app/views/layouts/error.html.erb .`
18
+
19
+ yield
20
+ ensure
21
+ `mv application.html.erb spec/fake_app/app/views/layouts/`
22
+ `mv error.html.erb spec/fake_app/app/views/layouts/`
11
23
  end
12
24
 
13
25
  scenario 'returns 422 json due to ActionController:InvalidAuthenticityToken but without its template' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rambulance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -191,18 +191,23 @@ files:
191
191
  - lib/generators/rambulance/templates/rambulance.rb
192
192
  - lib/generators/rambulance/templates/views/bad_request.html.erb
193
193
  - lib/generators/rambulance/templates/views/bad_request.html.haml
194
+ - lib/generators/rambulance/templates/views/bad_request.html.slim
194
195
  - lib/generators/rambulance/templates/views/bad_request.json.jbuilder
195
196
  - lib/generators/rambulance/templates/views/forbidden.html.erb
196
197
  - lib/generators/rambulance/templates/views/forbidden.html.haml
198
+ - lib/generators/rambulance/templates/views/forbidden.html.slim
197
199
  - lib/generators/rambulance/templates/views/forbidden.json.jbuilder
198
200
  - lib/generators/rambulance/templates/views/internal_server_error.html.erb
199
201
  - lib/generators/rambulance/templates/views/internal_server_error.html.haml
202
+ - lib/generators/rambulance/templates/views/internal_server_error.html.slim
200
203
  - lib/generators/rambulance/templates/views/internal_server_error.json.jbuilder
201
204
  - lib/generators/rambulance/templates/views/not_found.html.erb
202
205
  - lib/generators/rambulance/templates/views/not_found.html.haml
206
+ - lib/generators/rambulance/templates/views/not_found.html.slim
203
207
  - lib/generators/rambulance/templates/views/not_found.json.jbuilder
204
208
  - lib/generators/rambulance/templates/views/unprocessable_entity.html.erb
205
209
  - lib/generators/rambulance/templates/views/unprocessable_entity.html.haml
210
+ - lib/generators/rambulance/templates/views/unprocessable_entity.html.slim
206
211
  - lib/generators/rambulance/templates/views/unprocessable_entity.json.jbuilder
207
212
  - lib/rambulance.rb
208
213
  - lib/rambulance/exceptions_app.rb
@@ -241,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
246
  version: '0'
242
247
  requirements: []
243
248
  rubyforge_project:
244
- rubygems_version: 2.4.5
249
+ rubygems_version: 2.4.7
245
250
  signing_key:
246
251
  specification_version: 4
247
252
  summary: Simple and safe way to dynamically generate error pages