turnout 2.2.1 → 2.3.0

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: c460890aea93aba76cd44000ff00038bbdca6b66
4
- data.tar.gz: 7c409dc5de8a7ff7ebc6bffb7856aa37bec4dda5
3
+ metadata.gz: ac9fdc9be27c958015627a4af77649b9f0287522
4
+ data.tar.gz: af03a4ad0d8f762d8c64f456657455485f2b691e
5
5
  SHA512:
6
- metadata.gz: b3e4086a25d42b4e838942c343e41f09c3fbf173a14cc509cf7f86611b42fbd22918fe919dda8c0092ed7c3d484e2fd99f80a2a57be42188dda42eee8e8e9832
7
- data.tar.gz: 893483ca56460d50171c99520856c7e7434a303122aa3eda3d42c16bc5be018db4ee15d25cc6b15e1fcc65af05dfcab5274f6f873538d2e616ddf6b3ef828b2b
6
+ metadata.gz: 51ce8e2be2187cef06016585b2bb460fd2089d4ed7dacf6108ab5237d1742959aae542850bcb8e2da61e1bdfa41b32de780b5dcac64f8cfede82f02fb923e620
7
+ data.tar.gz: 08130e4a99769e06319e514d893991adc1451c965fcc155a5d5b08ba5f4510aa625f83498490211a5d445dd81d206fe996922587810b9f3c862262afc4df1a24
data/README.md CHANGED
@@ -66,7 +66,7 @@ or
66
66
  or
67
67
 
68
68
  rake maintenance:start reason="Someone told me I should type <code>sudo rm -rf /</code>" allowed_paths="^/help,^/contact_us" allowed_ips="127.0.0.1,192.168.0.0/24"
69
-
69
+
70
70
  or if you've configured `named_maintenance_file_paths` with a path named `server`
71
71
 
72
72
  rake maintenance:server:start
@@ -99,6 +99,7 @@ Turnout can be configured in two different ways:
99
99
  use Rack::Turnout,
100
100
  app_root: '/some/path',
101
101
  named_maintenance_file_paths: {app: 'tmp/app.yml', server: '/tmp/server.yml'},
102
+ maintenance_pages_path: 'app/views/maintenance',
102
103
  default_maintenance_page: Turnout::MaintenancePage::JSON,
103
104
  default_reason: 'Somebody googled Google!',
104
105
  default_allowed_paths: ['^/admin/'],
@@ -112,6 +113,7 @@ Turnout can be configured in two different ways:
112
113
  Turnout.configure do |config|
113
114
  config.app_root = '/some/path'
114
115
  config.named_maintenance_file_paths = {app: 'tmp/app.yml', server: '/tmp/server.yml'}
116
+ config.maintenance_pages_path = 'app/views/maintenance'
115
117
  config.default_maintenance_page = Turnout::MaintenancePage::JSON
116
118
  config.default_reason = 'Somebody googled Google!'
117
119
  config.default_allowed_paths = ['^/admin/']
@@ -129,6 +131,7 @@ Default Configuration
129
131
  Turnout.configure do |config|
130
132
  config.app_root = '.'
131
133
  config.named_maintenance_file_paths = {default: config.app_root.join('tmp', 'maintenance.yml').to_s}
134
+ config.maintenance_pages_path = config.app_root.join('public').to_s
132
135
  config.default_maintenance_page = Turnout::MaintenancePage::HTML
133
136
  config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
134
137
  config.default_allowed_paths = []
@@ -140,7 +143,10 @@ end
140
143
  Customization
141
144
  =============
142
145
 
143
- [Default maintenance pages](https://github.com/biola/turnout/blob/master/public/) are provided, but you can create your own `public/maintenance.[html|json]` files instead. If you provide a `reason` to the rake task, Turnout will parse the maintenance page file and attempt to replace a [Liquid](http://liquidmarkup.org/)-style `{{ reason }}` tag with the provided reason. So be sure to include a `{{ reason }}` tag in your `maintenance.html` file.
146
+ [Default maintenance pages](https://github.com/biola/turnout/blob/master/public/) are provided, but you can create your own `public/maintenance.[html|json|html.erb]` files instead. If you provide a `reason` to the rake task, Turnout will parse the maintenance page file and attempt to replace a [Liquid](http://liquidmarkup.org/)-style `{{ reason }}` tag with the provided reason. So be sure to include a `{{ reason }}` tag in your `maintenance.html` file. In the case of a `.html.erb` file, `reason` will be a local variable.
147
+
148
+ __WARNING:__
149
+ The source code of any custom maintenance files you created in the `/public` directory will be able to be viewed by visiting that URL directly (i.e. `http://example.com/maintenance.html.erb`). This shouldn't be an issue with HTML and JSON files but with ERB files, it could be. If you're going to use a custom `.erb.html` file, we recommend you change the `maintenance_pages_path` setting to something other than the `/public` directory.
144
150
 
145
151
  Tips
146
152
  ====
@@ -18,7 +18,7 @@ class Rack::Turnout
18
18
 
19
19
  if settings && !request.allowed?(settings)
20
20
  page_class = Turnout::MaintenancePage.best_for(env)
21
- page = page_class.new(settings.reason)
21
+ page = page_class.new(settings.reason, env: env)
22
22
 
23
23
  page.rack_response(settings.response_code, settings.retry_after)
24
24
  else
@@ -1,7 +1,8 @@
1
1
  module Turnout
2
2
  class Configuration
3
- SETTINGS = [:app_root, :named_maintenance_file_paths, :default_maintenance_page, :default_reason,
4
- :default_allowed_paths, :default_response_code, :default_retry_after]
3
+ SETTINGS = [:app_root, :named_maintenance_file_paths,
4
+ :maintenance_pages_path, :default_maintenance_page, :default_reason,
5
+ :default_allowed_paths, :default_response_code, :default_retry_after]
5
6
 
6
7
  SETTINGS.each do |setting|
7
8
  attr_accessor setting
@@ -10,6 +11,7 @@ module Turnout
10
11
  def initialize
11
12
  @app_root = '.'
12
13
  @named_maintenance_file_paths = {default: app_root.join('tmp', 'maintenance.yml').to_s}
14
+ @maintenance_pages_path = app_root.join('public').to_s
13
15
  @default_maintenance_page = Turnout::MaintenancePage::HTML
14
16
  @default_reason = "The site is temporarily down for maintenance.\nPlease check back soon."
15
17
  @default_allowed_paths = []
@@ -36,4 +38,4 @@ module Turnout
36
38
  end
37
39
  end
38
40
  end
39
- end
41
+ end
@@ -36,7 +36,7 @@ module Turnout
36
36
  end
37
37
 
38
38
  def write
39
- FileUtils.mkdir_p(dir_path) unless Dir.exists? dir_path
39
+ FileUtils.mkdir_p(dir_path) unless Dir.exist? dir_path
40
40
 
41
41
  File.open(path, 'w') do |file|
42
42
  file.write to_yaml
@@ -116,4 +116,4 @@ module Turnout
116
116
  Turnout.config.named_maintenance_file_paths
117
117
  end
118
118
  end
119
- end
119
+ end
@@ -1,3 +1,4 @@
1
+ require 'pathname'
1
2
  module Turnout
2
3
  module MaintenancePage
3
4
  require 'rack/accept'
@@ -11,14 +12,13 @@ module Turnout
11
12
 
12
13
  all_types = all.map(&:media_types).flatten
13
14
  best_type = request.best_media_type(all_types)
14
-
15
- best = all.find { |page| page.media_types.include? best_type }
16
-
15
+ best = all.find { |page| page.media_types.include?(best_type) && File.exist?(page.new.custom_path) }
17
16
  best || Turnout.config.default_maintenance_page
18
17
  end
19
18
 
20
19
  require 'turnout/maintenance_page/base'
20
+ require 'turnout/maintenance_page/erb'
21
21
  require 'turnout/maintenance_page/html'
22
22
  require 'turnout/maintenance_page/json'
23
23
  end
24
- end
24
+ end
@@ -3,7 +3,8 @@ module Turnout
3
3
  class Base
4
4
  attr_reader :reason
5
5
 
6
- def initialize(reason = nil)
6
+ def initialize(reason = nil, options = {})
7
+ @options = options.is_a?(Hash) ? options : {}
7
8
  @reason = reason
8
9
  end
9
10
 
@@ -24,6 +25,10 @@ module Turnout
24
25
  end
25
26
  def extension() self.class.extension end
26
27
 
28
+ def custom_path
29
+ Pathname.new(Turnout.config.maintenance_pages_path).join(filename)
30
+ end
31
+
27
32
  protected
28
33
 
29
34
  def self.inherited(subclass)
@@ -46,7 +51,7 @@ module Turnout
46
51
  end
47
52
 
48
53
  def content
49
- file_content.gsub /{{\s?reason\s?}}/, reason
54
+ file_content.gsub /{{\s?reason\s?}}/, reason
50
55
  end
51
56
 
52
57
  def file_content
@@ -65,9 +70,6 @@ module Turnout
65
70
  File.expand_path("../../../../public/#{filename}", __FILE__)
66
71
  end
67
72
 
68
- def custom_path
69
- Turnout.config.app_root.join('public', filename)
70
- end
71
73
 
72
74
  def filename
73
75
  "maintenance.#{extension}"
@@ -0,0 +1,18 @@
1
+ require 'erb'
2
+ require 'tilt'
3
+ require 'tilt/erb'
4
+ require_relative './html'
5
+ module Turnout
6
+ module MaintenancePage
7
+ class Erb < Turnout::MaintenancePage::HTML
8
+
9
+ def content
10
+ Tilt.new(File.expand_path(path)).render(nil, {reason: reason}.merge(@options))
11
+ end
12
+
13
+ def self.extension
14
+ 'html.erb'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,4 @@
1
+ require_relative './base'
1
2
  module Turnout
2
3
  module MaintenancePage
3
4
  class HTML < Base
@@ -17,4 +18,4 @@ module Turnout
17
18
  end
18
19
  end
19
20
  end
20
- end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Turnout
2
- VERSION = '2.2.1'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -0,0 +1,69 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Down for Maintenance</title>
6
+
7
+ <style type="text/css">
8
+
9
+ *{
10
+ font-family: Arial, Helvetica, sans-serif;
11
+ }
12
+
13
+ body{
14
+ margin: 0;
15
+ background-color: #fff;
16
+ }
17
+
18
+ #page{
19
+ position: relative;
20
+ width: 550px;
21
+ margin: 200px auto;
22
+ padding: 75px 0;
23
+ text-align: center;
24
+ background-color: #eaeaea;
25
+ border: solid 1px #ccc;
26
+ border-top: solid 10px #666;
27
+ -moz-box-shadow: inset 0 2px 10px #ccc;
28
+ -webkit-box-shadow: inset 0 2px 10px #ccc;
29
+ box-shadow: inset 0 2px 10px #ccc;
30
+ }
31
+
32
+ header, #body{
33
+ width: 400px;
34
+ margin: 0 auto;
35
+ }
36
+
37
+ h1{
38
+ margin: 0;
39
+ color: #CC3601;
40
+ font-size: 26pt;
41
+ border-bottom: solid 4px #666;
42
+ }
43
+
44
+ #reason{
45
+ margin: 10px 0;
46
+ color: #333;
47
+ }
48
+
49
+ </style>
50
+
51
+ </head>
52
+ <body>
53
+
54
+ <section id="page">
55
+
56
+ <header>
57
+ <h1>Down for Maintenance</h1>
58
+ </header>
59
+
60
+ <section id="body">
61
+ <div>
62
+ <%= reason %>
63
+ </div>
64
+ </section>
65
+
66
+ </section>
67
+
68
+ </body>
69
+ </html>
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: rack
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -97,12 +117,14 @@ files:
97
117
  - lib/turnout/maintenance_file.rb
98
118
  - lib/turnout/maintenance_page.rb
99
119
  - lib/turnout/maintenance_page/base.rb
120
+ - lib/turnout/maintenance_page/erb.rb
100
121
  - lib/turnout/maintenance_page/html.rb
101
122
  - lib/turnout/maintenance_page/json.rb
102
123
  - lib/turnout/rake_tasks.rb
103
124
  - lib/turnout/request.rb
104
125
  - lib/turnout/version.rb
105
126
  - public/maintenance.html
127
+ - public/maintenance.html.erb
106
128
  - public/maintenance.json
107
129
  homepage: https://github.com/biola/turnout
108
130
  licenses:
@@ -124,9 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
146
  version: '0'
125
147
  requirements: []
126
148
  rubyforge_project:
127
- rubygems_version: 2.2.2
149
+ rubygems_version: 2.5.1
128
150
  signing_key:
129
151
  specification_version: 4
130
152
  summary: A Rack based maintenance mode plugin for Rails
131
153
  test_files: []
132
- has_rdoc: