slimmer 15.5.0 → 15.5.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: cc08f967bc13790ee7db7c1ee0b8ef0aaf07f5d7fb904c6ef1f3e6ce16650287
4
- data.tar.gz: 8807bcfc49959843c3c1beeae148aa3c3a89e2dce1bb1ecbaf450543de62049f
3
+ metadata.gz: 9586ef4f9680eee337f141f0ca07d36786edf1a2e42db7324981fe0b7f64fdcd
4
+ data.tar.gz: 382289841b35dab136c22cefec16581bb5633f0cbe5036b8299e7d4f737c4159
5
5
  SHA512:
6
- metadata.gz: b2f694bacade80d4c78994adc2df5a0e9feaa202ca27bcf982cfa68142a31642ebbdde19fc7a2ef0222411a0a632ebbae969244f43d625644b25fb4bfd0fed85
7
- data.tar.gz: 063ee728d14b6342bbb53247a7bb231a5fea95f4f7aebc839cc67117a6ca104c8fdea8ce5dcdb2ab83f18dfebc7397d9dab6143bd384b9b13367b91e4d79d50e
6
+ metadata.gz: d065546672150a1ffa4d9ad548881770d9e62438d54902767d5bd9bc5386ae0b6122e6e5bfd3807a183b2aeb8bc131625962fdde64c3aaae4ec99f102dc378f0
7
+ data.tar.gz: 12bf26edb4237369c579e557e31773deb2341f9b088389c895d73609a860552f8518783589e49f4f7411bb6981b6d45be9c83d9b52336dd65a6d97a0b0bdd8e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 15.5.1
2
+ * Update gem_layout template support (#267)
3
+
1
4
  # 15.5.0
2
5
  * Add support for gem layout in static (#265)
3
6
 
@@ -23,8 +23,15 @@ module Slimmer::Processors
23
23
  remove_signed_out(dest)
24
24
  remove_signed_in(dest)
25
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
26
31
  end
27
32
 
33
+ private
34
+
28
35
  def remove_signed_out(dest)
29
36
  signed_out = dest.at_css("#global-header #accounts-signed-out")
30
37
  signed_out_link = dest.css(".gem-c-layout-header [data-link-for='accounts-signed-out']")
@@ -45,7 +52,9 @@ module Slimmer::Processors
45
52
  end
46
53
  end
47
54
 
48
- private
55
+ def is_navigation_empty?(dest)
56
+ dest.at_css(".govuk-header__navigation a").nil?
57
+ end
49
58
 
50
59
  def is_gem_layout?
51
60
  @headers[Slimmer::Headers::TEMPLATE_HEADER]&.starts_with?("gem_layout")
@@ -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
data/lib/slimmer/skin.rb CHANGED
@@ -101,13 +101,14 @@ 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),
111
112
  Processors::BodyClassCopier.new,
112
113
  Processors::InsideHeaderInserter.new,
113
114
  Processors::HeaderContextInserter.new,
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "15.5.0".freeze
2
+ VERSION = "15.5.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.5.0
4
+ version: 15.5.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-04-07 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport