slimmer 17.0.0 → 18.0.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
  SHA256:
3
- metadata.gz: 0a6d7eb900be169022598a1a09b96d08394d90e55ca451e611bc9de803f900f0
4
- data.tar.gz: 71243a607e6868ae847544cc1ed6d30acdf031f41b0572ac309fccf93e2814db
3
+ metadata.gz: a7a260effd72ec2553063c010694a0486e5990b664e5934332630b40586933a1
4
+ data.tar.gz: 70ebd575e41468a07f64c9ebff2e0b168a5cd890f5f32c736bfdbd70befdb1f2
5
5
  SHA512:
6
- metadata.gz: 3d986e7ec508d57b6d949272db05a0a5b25184ffe9195760671d1e72dc5f6397857ae0f5dc35936749ca0eb1cb7880e750a72f36a83d5dddc9792eada2349694
7
- data.tar.gz: 50f88ad62bb6530f70a8684f7427ce9933525440fbc131669526fc65ebdd8502c7d1e247771a54989842d77be31230b1e60b7f0692b3b5e91fa5767dbff5f73b
6
+ metadata.gz: 62607015532688137712ead664e2948e7581c739d6ecfc58b31164d1f63a8a15b652f8e750a2af23e4b0a5439e4a5d139862e8d0bc3cf3c3535c8d93b387a898
7
+ data.tar.gz: 6bd6af1f703e2d4ec1ce04dc2a883fbb7f208e9d24a3819e257e2d109fc067d0472ed96001d9e873385beab1a3a1aff41db781561d37ac2d383a817fac5b761c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 18.0.0
2
+
3
+ * BREAKING: Drop support for determining Rails < 6 application names
4
+ * BREAKING: Remove `bin/render_slimmer_error` as a feature - it's expected that this is unused.
5
+ * Require Ruby >= 2.7.0
6
+ * Resolve deprecation warning for Plek.current
7
+
1
8
  # 17.0.0
2
9
 
3
10
  * BREAKING: Set default template to `gem_layout` and remove references to the deprecated `core_layout`.
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
- require "rdoc/task"
3
2
  require "rake/testtask"
4
3
  require "rubocop/rake_task"
5
4
 
@@ -7,11 +6,6 @@ RuboCop::RakeTask.new
7
6
 
8
7
  Dir.glob("lib/tasks/*.rake").each { |r| import r }
9
8
 
10
- RDoc::Task.new do |rd|
11
- rd.rdoc_files.include("lib/**/*.rb")
12
- rd.rdoc_dir = "rdoc"
13
- end
14
-
15
9
  Rake::TestTask.new("test") do |t|
16
10
  t.ruby_opts << "-rrubygems"
17
11
  t.libs << "test"
@@ -19,4 +13,4 @@ Rake::TestTask.new("test") do |t|
19
13
  t.verbose = true
20
14
  end
21
15
 
22
- task default: %i[test rubocop]
16
+ task default: %i[rubocop test]
data/lib/slimmer/app.rb CHANGED
@@ -10,11 +10,9 @@ module Slimmer
10
10
 
11
11
  logger = options[:logger] || NullLogger.instance
12
12
  self.logger = logger
13
- if logger&.level&.zero? # Log set to debug level
14
- unless options[:enable_debugging]
15
- self.logger = logger.dup
16
- self.logger.level = 1 # info
17
- end
13
+ if logger&.level&.zero? && !(options[:enable_debugging])
14
+ self.logger = logger.dup
15
+ self.logger.level = 1 # info
18
16
  end
19
17
 
20
18
  if options.key? :template_path
@@ -22,7 +20,7 @@ module Slimmer
22
20
  end
23
21
 
24
22
  unless options[:asset_host]
25
- options[:asset_host] = Plek.current.find("static")
23
+ options[:asset_host] = Plek.find("static")
26
24
  end
27
25
 
28
26
  @skin = Skin.new options.merge(logger: self.logger)
@@ -95,7 +93,9 @@ module Slimmer
95
93
  end
96
94
 
97
95
  def strip_slimmer_headers(headers)
98
- headers.reject { |k, _v| k =~ /\A#{Headers::HEADER_PREFIX}/ }
96
+ # Convert Rack::Util::HeaderHash to a simple hash to avoid a Ruby warning
97
+ # of extra states not copied. Can be removed once Ruby < 3.1 support is removed.
98
+ headers.to_h.reject { |k, _v| k =~ /\A#{Headers::HEADER_PREFIX}/ }
99
99
  end
100
100
  end
101
101
  end
@@ -15,9 +15,10 @@ module Slimmer::Processors
15
15
  layout_header.remove if layout_header
16
16
  end
17
17
 
18
- if header_value == "signed-in"
18
+ case header_value
19
+ when "signed-in"
19
20
  remove_signed_out(dest)
20
- elsif header_value == "signed-out"
21
+ when "signed-out"
21
22
  remove_signed_in(dest)
22
23
  else
23
24
  remove_signed_out(dest)
@@ -57,7 +58,7 @@ module Slimmer::Processors
57
58
  end
58
59
 
59
60
  def is_gem_layout?
60
- @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
61
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.start_with?("gem_layout")
61
62
  end
62
63
  end
63
64
  end
@@ -1,8 +1,8 @@
1
1
  module Slimmer::Processors
2
2
  class BodyInserter
3
3
  def initialize(source_id = "wrapper", destination_id = "wrapper", headers = {})
4
- @source_selector = "#" + source_id
5
- @destination_selector = "#" + destination_id
4
+ @source_selector = "##{source_id}"
5
+ @destination_selector = "##{destination_id}"
6
6
  @headers = headers
7
7
  end
8
8
 
@@ -22,7 +22,7 @@ module Slimmer::Processors
22
22
  private
23
23
 
24
24
  def is_gem_layout?
25
- @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
25
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.start_with?("gem_layout")
26
26
  end
27
27
  end
28
28
  end
@@ -28,7 +28,7 @@ module Slimmer::Processors
28
28
  end
29
29
 
30
30
  def is_gem_layout?
31
- @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
31
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.start_with?("gem_layout")
32
32
  end
33
33
  end
34
34
  end
@@ -4,20 +4,14 @@ module Slimmer
4
4
 
5
5
  initializer "slimmer.configure" do |app|
6
6
  slimmer_config = app.config.slimmer.to_hash
7
- app_name = ENV["GOVUK_APP_NAME"] || Slimmer::Railtie.parent_name(app)
7
+ parent_name = app.class.module_parent_name if app.class.respond_to?(:module_parent_name)
8
+ app_name = ENV.fetch("GOVUK_APP_NAME", parent_name)
8
9
  slimmer_config = slimmer_config.reverse_merge(app_name: app_name)
9
10
 
10
- app.middleware.use Slimmer::App, slimmer_config
11
- end
12
-
13
- # TODO: remove this method when all our apps are in rails 6 and substitute
14
- # it with: app_name = ENV['GOVUK_APP_NAME'] || app.class.module_parent_name
15
- def self.parent_name(app)
16
- if app.class.respond_to?(:module_parent_name)
17
- app.class.module_parent_name
18
- else
19
- app.class.parent_name
20
- end
11
+ # The extra kwargs **{} is for Ruby 2.7 so that it doesn't recognise the
12
+ # slimmer_config as kwargs, this change can be removed once Ruby 2.7
13
+ # support is dropped
14
+ app.middleware.use Slimmer::App, slimmer_config, **{}
21
15
  end
22
16
  end
23
17
  end
data/lib/slimmer/skin.rb CHANGED
@@ -68,7 +68,7 @@ module Slimmer
68
68
  from = [1, error.line - context_size].max
69
69
  to = [lines.size - 1, error.line + context_size].min
70
70
  context = (from..to).zip(lines[from..to]).map { |lineno, line| sprintf("%4d: %s", lineno, line) }
71
- marker = " " * (error.column - 1) + "-----v"
71
+ marker = "#{' ' * (error.column - 1)}-----v"
72
72
  context.insert(context_size, marker)
73
73
  context.join("\n")
74
74
  end
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "17.0.0".freeze
2
+ VERSION = "18.0.0".freeze
3
3
  end
data/lib/slimmer.rb CHANGED
@@ -9,6 +9,10 @@ require "slimmer/railtie" if defined? Rails
9
9
  module Slimmer
10
10
  CACHE_TTL = 60
11
11
 
12
+ def self.cache=(cache)
13
+ @cache = cache
14
+ end
15
+
12
16
  def self.cache
13
17
  @cache ||= defined?(Rails) ? Rails.cache : NoCache.new
14
18
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 17.0.0
4
+ version: 18.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -109,143 +95,113 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: minitest
98
+ name: climate_control
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: '5.4'
103
+ version: '1.1'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: '5.4'
110
+ version: '1.1'
125
111
  - !ruby/object:Gem::Dependency
126
- name: mocha
112
+ name: minitest
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '1.1'
117
+ version: '5.16'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '1.1'
124
+ version: '5.16'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: rack-test
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: 0.6.1
131
+ version: '2'
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 0.6.1
138
+ version: '2'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: rails
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: 6.0.2
145
+ version: '7'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: 6.0.2
152
+ version: '7'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: rake
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - "~>"
157
+ - - ">="
172
158
  - !ruby/object:Gem::Version
173
- version: 0.9.2.2
159
+ version: '0'
174
160
  type: :development
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
- - - "~>"
164
+ - - ">="
179
165
  - !ruby/object:Gem::Version
180
- version: 0.9.2.2
166
+ version: '0'
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: rubocop-govuk
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '3'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '3'
195
- - !ruby/object:Gem::Dependency
196
- name: timecop
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 0.5.1
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 0.5.1
209
- - !ruby/object:Gem::Dependency
210
- name: webmock
211
169
  requirement: !ruby/object:Gem::Requirement
212
170
  requirements:
213
171
  - - '='
214
172
  - !ruby/object:Gem::Version
215
- version: 3.5.0
173
+ version: 4.7.0
216
174
  type: :development
217
175
  prerelease: false
218
176
  version_requirements: !ruby/object:Gem::Requirement
219
177
  requirements:
220
178
  - - '='
221
179
  - !ruby/object:Gem::Version
222
- version: 3.5.0
180
+ version: 4.7.0
223
181
  - !ruby/object:Gem::Dependency
224
- name: yard
182
+ name: webmock
225
183
  requirement: !ruby/object:Gem::Requirement
226
184
  requirements:
227
- - - '='
185
+ - - "~>"
228
186
  - !ruby/object:Gem::Version
229
- version: 0.8.7.6
187
+ version: '3.8'
230
188
  type: :development
231
189
  prerelease: false
232
190
  version_requirements: !ruby/object:Gem::Requirement
233
191
  requirements:
234
- - - '='
192
+ - - "~>"
235
193
  - !ruby/object:Gem::Version
236
- version: 0.8.7.6
194
+ version: '3.8'
237
195
  description: Rack middleware for skinning pages using a specific template
238
196
  email:
239
197
  - govuk-dev@digital.cabinet-office.gov.uk
240
- executables:
241
- - render_slimmer_error
198
+ executables: []
242
199
  extensions: []
243
200
  extra_rdoc_files: []
244
201
  files:
245
202
  - CHANGELOG.md
246
203
  - README.md
247
204
  - Rakefile
248
- - bin/render_slimmer_error
249
205
  - lib/slimmer.rb
250
206
  - lib/slimmer/app.rb
251
207
  - lib/slimmer/cucumber.rb
@@ -285,16 +241,16 @@ require_paths:
285
241
  - lib
286
242
  required_ruby_version: !ruby/object:Gem::Requirement
287
243
  requirements:
288
- - - ">="
244
+ - - ">"
289
245
  - !ruby/object:Gem::Version
290
- version: '0'
246
+ version: 2.7.0
291
247
  required_rubygems_version: !ruby/object:Gem::Requirement
292
248
  requirements:
293
249
  - - ">="
294
250
  - !ruby/object:Gem::Version
295
251
  version: '0'
296
252
  requirements: []
297
- rubygems_version: 3.1.4
253
+ rubygems_version: 3.3.24
298
254
  signing_key:
299
255
  specification_version: 4
300
256
  summary: Thinner than the skinner
@@ -1,39 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require "optparse"
4
- require "slimmer"
5
- require "logger"
6
-
7
- options = {}
8
- option_parser = OptionParser.new do |opts|
9
- opts.on "-t", "--template=TEMPLATE", "Template to render" do |v|
10
- options[:template] = v
11
- end
12
-
13
- opts.on "-h", "--asset-host=HOST", "Host that serves assets used in the template" do |v|
14
- options[:asset_host] = v
15
- end
16
-
17
- opts.on "-o", "--output-file=FILE", "File to write static error page to" do |v|
18
- options[:file] = v
19
- end
20
- end
21
-
22
- option_parser.parse!
23
-
24
- raise "Please specify a template" unless options[:template]
25
- raise "Please specify an asset host" unless options[:asset_host]
26
- raise "Please specify an output file" unless options[:file]
27
-
28
- logger = Logger.new STDOUT
29
- logger.level = Logger::DEBUG
30
- skin = Slimmer::Skin.new options[:asset_host], false, logger: logger
31
- static_error = skin.error nil, options[:template], Nokogiri::HTML("").to_html
32
-
33
- if options[:file] == "-"
34
- STDOUT.print static_error
35
- else
36
- File.open options[:file], "w" do |f|
37
- f.print static_error
38
- end
39
- end