slimmer 15.4.0 → 15.6.1

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: 863bbe9dee726275663817de72e9565a12f648b792d49e736d87bba0d0de9367
4
- data.tar.gz: 946b29270aa371b28a6b8c7e910e263bb0718f48bd337922de79a6bb1ce1475e
3
+ metadata.gz: b50a2f579bef76ba7364de07eaebbf2be8ed7fcbfcb3a2818ff3005a18a65007
4
+ data.tar.gz: 8b1a553d9ccb0b12bef74edd0e9913d440908bf24fce8c529786b092187bf410
5
5
  SHA512:
6
- metadata.gz: 823996625c9137fa1139ab7ea3d32f28f17c1d77edcbf2c4613c6038a6fa1c80263972c1d5cdeceb9dbabcd9c6985d6d183335034e97c43e32da3d290e8338c8
7
- data.tar.gz: bdc96ffc6f0d51f93733158873fc12b0fb8a01de806cbfca43b3a40570787cb3564f25ad1f019bb763e38a276e14fa7134e7a030a344f12aca9386e937e19a0d
6
+ metadata.gz: bb82513d196832bc2ce53e88458d19db078c2a73092f88770d101ef6d42323336a9e42ef0537ed132e5233be593a333fb7cdabfd024406d44a735f3a39d2e7e6
7
+ data.tar.gz: 176ffae950e7168365582f5e4956b5cea438582e4e43083132b67014f4d0f8ebbe76370f2f1b2f6264aca221aead761a8a27bf86bd7bde0b5a4c123e7aa73655
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # 15.6.1
2
+ * Use safe navigation operator in feedback url swapper (#273)
3
+
4
+ # 15.6.0
5
+
6
+ * Add feedback url swapper (#271)
7
+
8
+ # 15.5.1
9
+ * Update gem_layout template support (#267)
10
+
11
+ # 15.5.0
12
+ * Add support for gem layout in static (#265)
13
+
14
+ # 15.4.1
15
+
16
+ * Add support for layout header component in static (#263)
17
+
1
18
  # 15.4.0
2
19
 
3
20
  * Hoist `<async>` and `<defer>` JS Script tags to `<head>`. (#261)
data/lib/slimmer.rb CHANGED
@@ -32,6 +32,7 @@ module Slimmer
32
32
  autoload :BodyClassCopier, "slimmer/processors/body_class_copier"
33
33
  autoload :BodyInserter, "slimmer/processors/body_inserter"
34
34
  autoload :ConditionalCommentMover, "slimmer/processors/conditional_comment_mover"
35
+ autoload :FeedbackURLSwapper, "slimmer/processors/feedback_url_swapper"
35
36
  autoload :MetadataInserter, "slimmer/processors/metadata_inserter"
36
37
  autoload :HeaderContextInserter, "slimmer/processors/header_context_inserter"
37
38
  autoload :InsideHeaderInserter, "slimmer/processors/inside_header_inserter"
@@ -6,6 +6,15 @@ module Slimmer::Processors
6
6
 
7
7
  def filter(_src, dest)
8
8
  header_value = @headers[Slimmer::Headers::SHOW_ACCOUNTS_HEADER]
9
+ layout_header = dest.at_css(".gem-c-layout-header")
10
+ static_header = dest.at_css("#global-header")
11
+
12
+ if header_value && layout_header
13
+ static_header.remove if static_header
14
+ elsif !header_value && !is_gem_layout?
15
+ layout_header.remove if layout_header
16
+ end
17
+
9
18
  if header_value == "signed-in"
10
19
  remove_signed_out(dest)
11
20
  elsif header_value == "signed-out"
@@ -14,16 +23,41 @@ module Slimmer::Processors
14
23
  remove_signed_out(dest)
15
24
  remove_signed_in(dest)
16
25
  end
26
+
27
+ if is_navigation_empty?(dest)
28
+ header_content = dest.at_css(".govuk-header__content")
29
+ header_content.remove if header_content
30
+ end
17
31
  end
18
32
 
33
+ private
34
+
19
35
  def remove_signed_out(dest)
20
36
  signed_out = dest.at_css("#global-header #accounts-signed-out")
37
+ signed_out_link = dest.css(".gem-c-layout-header [data-link-for='accounts-signed-out']")
38
+
21
39
  signed_out.remove if signed_out
40
+ signed_out_link.each do |link|
41
+ link.parent.remove
42
+ end
22
43
  end
23
44
 
24
45
  def remove_signed_in(dest)
25
46
  signed_in = dest.at_css("#global-header #accounts-signed-in")
47
+ signed_in_link = dest.css(".gem-c-layout-header [data-link-for='accounts-signed-in']")
48
+
26
49
  signed_in.remove if signed_in
50
+ signed_in_link.each do |link|
51
+ link.parent.remove
52
+ end
53
+ end
54
+
55
+ def is_navigation_empty?(dest)
56
+ dest.at_css(".govuk-header__navigation a").nil?
57
+ end
58
+
59
+ def is_gem_layout?
60
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
27
61
  end
28
62
  end
29
63
  end
@@ -1,13 +1,28 @@
1
1
  module Slimmer::Processors
2
2
  class BodyInserter
3
- def initialize(source_id = "wrapper", destination_id = "wrapper")
3
+ def initialize(source_id = "wrapper", destination_id = "wrapper", headers = {})
4
4
  @source_selector = "#" + source_id
5
5
  @destination_selector = "#" + destination_id
6
+ @headers = headers
6
7
  end
7
8
 
8
9
  def filter(src, dest)
9
- body = Nokogiri::HTML.fragment(src.at_css(@source_selector).to_html)
10
+ source_markup = src.at_css(@source_selector)
11
+ destination_markup = dest.at_css(@destination_selector)
12
+
13
+ css_classes = []
14
+ css_classes << source_markup.attributes["class"].to_s.split(/ +/) if source_markup.has_attribute?("class")
15
+ css_classes << destination_markup.attributes["class"].to_s.split(/ +/) if destination_markup.has_attribute?("class")
16
+
17
+ body = Nokogiri::HTML.fragment(source_markup.to_html)
10
18
  dest.at_css(@destination_selector).replace(body)
19
+ dest.at_css(@destination_selector).set_attribute("class", css_classes.flatten.uniq.join(" ")) if is_gem_layout? && css_classes.any?
20
+ end
21
+
22
+ private
23
+
24
+ def is_gem_layout?
25
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
11
26
  end
12
27
  end
13
28
  end
@@ -0,0 +1,34 @@
1
+ module Slimmer::Processors
2
+ class FeedbackURLSwapper
3
+ def initialize(request, headers)
4
+ @headers = headers
5
+ @request = request
6
+ end
7
+
8
+ def filter(_src, dest)
9
+ return dest unless is_gem_layout?
10
+
11
+ original_url_without_pii = remove_pii(@request.base_url + @request.fullpath)
12
+ dest.at_css(".gem-c-feedback input[name='url']")&.set_attribute("value", original_url_without_pii)
13
+
14
+ full_path_without_pii = remove_pii(@request.fullpath)
15
+ dest.at_css(".gem-c-feedback input[name='email_survey_signup[survey_source]']")&.set_attribute("value", full_path_without_pii)
16
+
17
+ dest
18
+ end
19
+
20
+ private
21
+
22
+ # This PII removal is also found in the [feedback component in the GOV.UK
23
+ # Publishing Components gem](https://git.io/JcCIE), and any changes made
24
+ # need to be kept in sync.
25
+ def remove_pii(string)
26
+ email_regex = /[^\s=\/?&]+(?:@|%40)[^\s=\/?&]+/
27
+ string.dup.force_encoding("UTF-8").gsub(email_regex, "[email]")
28
+ end
29
+
30
+ def is_gem_layout?
31
+ @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
32
+ end
33
+ end
34
+ end
@@ -11,6 +11,9 @@ module Slimmer::Processors
11
11
 
12
12
  search_link = dest.at_css("#global-header .search-toggle")
13
13
  search_link.remove if search_link
14
+
15
+ gem_search = dest.at_css(".gem-c-layout-header__search")
16
+ gem_search.remove if gem_search
14
17
  end
15
18
  end
16
19
  end
data/lib/slimmer/skin.rb CHANGED
@@ -101,13 +101,15 @@ module Slimmer
101
101
 
102
102
  def success(source_request, response, body)
103
103
  wrapper_id = options[:wrapper_id] || "wrapper"
104
+ template_wrapper_id = "wrapper" # All templates in Static use `#wrapper`
104
105
 
105
106
  processors = [
106
107
  Processors::TitleInserter.new,
107
108
  Processors::TagMover.new,
108
109
  Processors::NavigationMover.new(self),
109
110
  Processors::ConditionalCommentMover.new,
110
- Processors::BodyInserter.new(wrapper_id),
111
+ Processors::BodyInserter.new(wrapper_id, template_wrapper_id, response.headers),
112
+ Processors::FeedbackURLSwapper.new(source_request, response.headers),
111
113
  Processors::BodyClassCopier.new,
112
114
  Processors::InsideHeaderInserter.new,
113
115
  Processors::HeaderContextInserter.new,
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "15.4.0".freeze
2
+ VERSION = "15.6.1".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.4.0
4
+ version: 15.6.1
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: 2021-01-20 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -256,6 +256,7 @@ files:
256
256
  - lib/slimmer/processors/body_class_copier.rb
257
257
  - lib/slimmer/processors/body_inserter.rb
258
258
  - lib/slimmer/processors/conditional_comment_mover.rb
259
+ - lib/slimmer/processors/feedback_url_swapper.rb
259
260
  - lib/slimmer/processors/header_context_inserter.rb
260
261
  - lib/slimmer/processors/inside_header_inserter.rb
261
262
  - lib/slimmer/processors/metadata_inserter.rb