Class: Slimmer::Processors::AccountsShower

Inherits:
Object
  • Object
show all
Defined in:
lib/slimmer/processors/accounts_shower.rb

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ AccountsShower

Returns a new instance of AccountsShower.



3
4
5
# File 'lib/slimmer/processors/accounts_shower.rb', line 3

def initialize(headers)
  @headers = headers
end

Instance Method Details

#filter(_src, dest) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/slimmer/processors/accounts_shower.rb', line 7

def filter(_src, dest)
  header_value = @headers[Slimmer::Headers::SHOW_ACCOUNTS_HEADER]
  layout_header = dest.at_css(".gem-c-layout-header")
  static_header = dest.at_css("#global-header")

  if header_value && layout_header
    static_header.remove if static_header
  elsif !header_value && !is_gem_layout?
    layout_header.remove if layout_header
  end

  case header_value
  when "signed-in"
    remove_signed_out(dest)
  when "signed-out"
    remove_signed_in(dest)
  else
    remove_signed_out(dest)
    remove_signed_in(dest)
  end

  if is_navigation_empty?(dest)
    header_content = dest.at_css(".govuk-header__content")
    header_content.remove if header_content
  end
end