slimmer 15.0.0 → 15.4.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: 69efc7036b8f43e79f0a658b8cb7a4d1b8a3a6d6e7083adc4f0d7c5f94660de4
4
- data.tar.gz: 1ea0fc004cc8eaf7b51db1071aa6d681bd178aa4f28e311a5c8c896330a2a0d0
3
+ metadata.gz: 863bbe9dee726275663817de72e9565a12f648b792d49e736d87bba0d0de9367
4
+ data.tar.gz: 946b29270aa371b28a6b8c7e910e263bb0718f48bd337922de79a6bb1ce1475e
5
5
  SHA512:
6
- metadata.gz: 526e412c02dec4300125ef6047212538dea07fecf9842b0cfb2716e7f962c582b76ff921107ca3b039c053718a310adc29fe6d7035fb3544c5b0f66b73b83b4e
7
- data.tar.gz: d414a38146b156fc6ba454798fe79741bff8b3f3015d42dad4b991e8f5f48e1bf9f0c46b2de7cb079c78b9beb62eeb9925c23ed5514c5a67d80b5e249b31fa83
6
+ metadata.gz: 823996625c9137fa1139ab7ea3d32f28f17c1d77edcbf2c4613c6038a6fa1c80263972c1d5cdeceb9dbabcd9c6985d6d183335034e97c43e32da3d290e8338c8
7
+ data.tar.gz: bdc96ffc6f0d51f93733158873fc12b0fb8a01de806cbfca43b3a40570787cb3564f25ad1f019bb763e38a276e14fa7134e7a030a344f12aca9386e937e19a0d
@@ -1,3 +1,26 @@
1
+ # 15.4.0
2
+
3
+ * Hoist `<async>` and `<defer>` JS Script tags to `<head>`. (#261)
4
+
5
+ # 15.3.0
6
+
7
+ * Introduce separate, internal exception class for intermittent
8
+ template retrieval errors.
9
+
10
+ # 15.2.0
11
+
12
+ * Add X-Slimmer-Show-Accounts header to choose between accounts
13
+ header components. (#255)
14
+ * Update to Ruby 2.7.2. (#254)
15
+
16
+ # 15.1.1
17
+
18
+ * Amend toggle button selector (#251)
19
+
20
+ # 15.1.0
21
+
22
+ * Add `<base>` tag into the `<head>`.
23
+
1
24
  # 15.0.0
2
25
 
3
26
  * BREAKING: Test templates no longer embed links to production JavaScript files,
@@ -28,15 +28,14 @@ module Slimmer
28
28
  autoload :HTTPClient, "slimmer/http_client"
29
29
 
30
30
  module Processors
31
+ autoload :AccountsShower, "slimmer/processors/accounts_shower"
31
32
  autoload :BodyClassCopier, "slimmer/processors/body_class_copier"
32
33
  autoload :BodyInserter, "slimmer/processors/body_inserter"
33
34
  autoload :ConditionalCommentMover, "slimmer/processors/conditional_comment_mover"
34
- autoload :FooterRemover, "slimmer/processors/footer_remover"
35
35
  autoload :MetadataInserter, "slimmer/processors/metadata_inserter"
36
36
  autoload :HeaderContextInserter, "slimmer/processors/header_context_inserter"
37
37
  autoload :InsideHeaderInserter, "slimmer/processors/inside_header_inserter"
38
38
  autoload :NavigationMover, "slimmer/processors/navigation_mover"
39
- autoload :SearchIndexSetter, "slimmer/processors/search_index_setter"
40
39
  autoload :SearchPathSetter, "slimmer/processors/search_path_setter"
41
40
  autoload :SearchParameterInserter, "slimmer/processors/search_parameter_inserter"
42
41
  autoload :SearchRemover, "slimmer/processors/search_remover"
@@ -44,6 +43,7 @@ module Slimmer
44
43
  autoload :TitleInserter, "slimmer/processors/title_inserter"
45
44
  end
46
45
 
47
- class TemplateNotFoundException < StandardError; end
48
46
  class CouldNotRetrieveTemplate < StandardError; end
47
+ class TemplateNotFoundException < CouldNotRetrieveTemplate; end
48
+ class IntermittentRetrievalError < CouldNotRetrieveTemplate; end
49
49
  end
@@ -20,6 +20,7 @@ module Slimmer
20
20
  skip: "Skip",
21
21
  template: "Template",
22
22
  remove_search: "Remove-Search",
23
+ show_accounts: "Show-Accounts",
23
24
  }.freeze
24
25
 
25
26
  # @private
@@ -55,6 +56,9 @@ module Slimmer
55
56
  # @private
56
57
  REMOVE_SEARCH_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:remove_search]}".freeze
57
58
 
59
+ # @private
60
+ SHOW_ACCOUNTS_HEADER = "#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:show_accounts]}".freeze
61
+
58
62
  # Set the "slimmer headers" to configure the page
59
63
  #
60
64
  # @param hash [Hash] the options
@@ -66,6 +70,7 @@ module Slimmer
66
70
  # @option hash [String] result_count
67
71
  # @option hash [String] search_parameters
68
72
  # @option hash [String] section
73
+ # @option hash [String] show_accounts
69
74
  # @option hash [String] skip
70
75
  # @option hash [String] template
71
76
  # @option hash [String] world_locations
@@ -0,0 +1,29 @@
1
+ module Slimmer::Processors
2
+ class AccountsShower
3
+ def initialize(headers)
4
+ @headers = headers
5
+ end
6
+
7
+ def filter(_src, dest)
8
+ header_value = @headers[Slimmer::Headers::SHOW_ACCOUNTS_HEADER]
9
+ if header_value == "signed-in"
10
+ remove_signed_out(dest)
11
+ elsif header_value == "signed-out"
12
+ remove_signed_in(dest)
13
+ else
14
+ remove_signed_out(dest)
15
+ remove_signed_in(dest)
16
+ end
17
+ end
18
+
19
+ def remove_signed_out(dest)
20
+ signed_out = dest.at_css("#global-header #accounts-signed-out")
21
+ signed_out.remove if signed_out
22
+ end
23
+
24
+ def remove_signed_in(dest)
25
+ signed_in = dest.at_css("#global-header #accounts-signed-in")
26
+ signed_in.remove if signed_in
27
+ end
28
+ end
29
+ end
@@ -9,7 +9,7 @@ module Slimmer::Processors
9
9
  search = dest.at_css("#global-header #search")
10
10
  search.remove if search
11
11
 
12
- search_link = dest.at_css("#global-header a[href='#search']")
12
+ search_link = dest.at_css("#global-header .search-toggle")
13
13
  search_link.remove if search_link
14
14
  end
15
15
  end
@@ -1,10 +1,11 @@
1
1
  module Slimmer::Processors
2
2
  class TagMover
3
3
  def filter(src, dest)
4
- move_tags(src, dest, "script", dest_node: "body", keys: %w[src inner_html])
5
4
  move_tags(src, dest, "link", must_have: %w[href])
6
5
  move_tags(src, dest, "meta", must_have: %w[name content], keys: %w[name content http-equiv], insertion_location: :top)
7
6
  move_tags(src, dest, "meta", must_have: %w[property content], keys: %w[property content], insertion_location: :top)
7
+ move_tags(src, dest, "base", must_have: %w[href])
8
+ move_tags(src, dest, "script", keys: %w[src inner_html], head_if_attributes: %w[async defer])
8
9
  end
9
10
 
10
11
  def include_tag?(node, min_attrs)
@@ -30,21 +31,34 @@ module Slimmer::Processors
30
31
  node
31
32
  end
32
33
 
34
+ def head_or_body(node, head_if_attributes)
35
+ if head_if_attributes.any? { |attribute| node.has_attribute?(attribute) }
36
+ "head"
37
+ else
38
+ "body"
39
+ end
40
+ end
41
+
33
42
  def move_tags(src, dest, type, opts)
34
43
  comparison_attrs = opts[:keys] || opts[:must_have]
35
44
  min_attrs = opts[:must_have] || []
45
+ head_if_attributes = opts[:head_if_attributes] || []
46
+ dest_node = "head"
36
47
  already_there = dest.css(type).map { |node|
37
48
  tag_fingerprint(node, comparison_attrs)
38
49
  }.compact
39
- dest_node = opts[:dest_node] || "head"
40
50
 
41
51
  src.css(type).each do |node|
42
52
  next unless include_tag?(node, min_attrs) && !already_there.include?(tag_fingerprint(node, comparison_attrs))
43
53
 
44
54
  node = wrap_node(src, node)
55
+ if head_if_attributes.any?
56
+ dest_node = head_or_body(node, head_if_attributes)
57
+ insert_at_top = true if dest_node == "head"
58
+ end
45
59
  node.remove
46
60
 
47
- if opts[:insertion_location] == :top
61
+ if opts[:insertion_location] == :top || insert_at_top
48
62
  dest.at_xpath("/html/#{dest_node}").prepend_child(node)
49
63
  else
50
64
  dest.at_xpath("/html/#{dest_node}") << node
@@ -22,10 +22,18 @@ module Slimmer
22
22
  def load_template(template_name)
23
23
  url = template_url(template_name)
24
24
  HTTPClient.get(url)
25
- rescue RestClient::Exception => e
26
- raise TemplateNotFoundException, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
27
- rescue Errno::ECONNREFUSED, SocketError, OpenSSL::SSL::SSLError => e
28
- raise CouldNotRetrieveTemplate, "Unable to fetch: '#{template_name}' from '#{url}' because #{e}", caller
25
+ rescue Errno::ECONNREFUSED, SocketError, OpenSSL::SSL::SSLError, RestClient::Exception => e
26
+ message = "Unable to fetch: '#{template_name}' from '#{url}' because #{e}"
27
+
28
+ if e.is_a?(RestClient::Exception) && e.http_code == 404
29
+ raise TemplateNotFoundException, message, caller
30
+ end
31
+
32
+ if e.is_a?(RestClient::Exception) && [502, 503, 504].include?(e.http_code)
33
+ raise IntermittentRetrievalError, message, caller
34
+ end
35
+
36
+ raise CouldNotRetrieveTemplate, message, caller
29
37
  end
30
38
 
31
39
  def template_url(template_name)
@@ -107,6 +115,7 @@ module Slimmer
107
115
  Processors::SearchParameterInserter.new(response),
108
116
  Processors::SearchPathSetter.new(response),
109
117
  Processors::SearchRemover.new(response.headers),
118
+ Processors::AccountsShower.new(response.headers),
110
119
  ]
111
120
 
112
121
  template_name = response.headers[Headers::TEMPLATE_HEADER] || "core_layout"
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "15.0.0".freeze
2
+ VERSION = "15.4.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.0.0
4
+ version: 15.4.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: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -252,10 +252,10 @@ files:
252
252
  - lib/slimmer/govuk_request_id.rb
253
253
  - lib/slimmer/headers.rb
254
254
  - lib/slimmer/http_client.rb
255
+ - lib/slimmer/processors/accounts_shower.rb
255
256
  - lib/slimmer/processors/body_class_copier.rb
256
257
  - lib/slimmer/processors/body_inserter.rb
257
258
  - lib/slimmer/processors/conditional_comment_mover.rb
258
- - lib/slimmer/processors/footer_remover.rb
259
259
  - lib/slimmer/processors/header_context_inserter.rb
260
260
  - lib/slimmer/processors/inside_header_inserter.rb
261
261
  - lib/slimmer/processors/metadata_inserter.rb
@@ -294,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  - !ruby/object:Gem::Version
295
295
  version: '0'
296
296
  requirements: []
297
- rubygems_version: 3.0.3
297
+ rubygems_version: 3.1.4
298
298
  signing_key:
299
299
  specification_version: 4
300
300
  summary: Thinner than the skinner
@@ -1,8 +0,0 @@
1
- module Slimmer::Processors
2
- class FooterRemover
3
- def filter(src, _dest)
4
- footer = src.at_css("#footer")
5
- footer.remove if footer
6
- end
7
- end
8
- end