slimmer 3.3.3 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,17 +4,31 @@ module Slimmer::Processors
4
4
  @artefact = artefact
5
5
  end
6
6
 
7
- def filter(src,dest)
7
+ def filter(src, dest)
8
8
  if @artefact and (list = dest.at_css('.header-context nav[role=navigation] ol'))
9
9
  if (section = @artefact.primary_section)
10
- append_tag(list, section["parent"]) if section["parent"]
11
- append_tag(list, section, :strong => true)
10
+ sections = recurse_sections(section)
11
+ current = sections.pop
12
+ sections.each do |section|
13
+ append_tag(list, section)
14
+ end
15
+ append_tag(list, current, :strong => true)
12
16
  end
13
17
  end
14
18
  end
15
19
 
16
20
  private
17
21
 
22
+ def recurse_sections(section, current = nil)
23
+ current = [section] unless current
24
+
25
+ if section['parent']
26
+ current.unshift(section['parent'])
27
+ current = recurse_sections(section['parent'], current)
28
+ end
29
+ current
30
+ end
31
+
18
32
  def append_tag(list, tag, opts = {})
19
33
  link_node = Nokogiri::XML::Node.new('a', list)
20
34
  link_node['href'] = tag["content_with_tag"]["web_url"]
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.3.3'
2
+ VERSION = '3.4.0'
3
3
  end
@@ -146,4 +146,34 @@ class SectionInserterTest < MiniTest::Unit::TestCase
146
146
  list = template.at_css(".header-context nav[role=navigation] ol")
147
147
  assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
148
148
  end
149
+
150
+ def test_should_support_multiple_levels_of_navigation
151
+ artefact = create_artefact("something",
152
+ "section_slug" => "business",
153
+ "subsection_slug" => "employing-people/deep-section")
154
+
155
+ template = as_nokogiri %{
156
+ <html>
157
+ <body>
158
+ <div class="header-context">
159
+ <nav role="navigation">
160
+ <ol class="group">
161
+ <li><a href="/">Home</a></li>
162
+ <li><a href="/browse">All Sections</a></li>
163
+ </ol>
164
+ </nav>
165
+ </div>
166
+ </body>
167
+ </html>
168
+ }
169
+
170
+ Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
171
+ list = template.at_css(".header-context nav[role=navigation] ol")
172
+ assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
173
+ assert_in list, "li:nth-child(2)", %{<a href="/browse">All Sections</a>}
174
+ assert_in list, "li:nth-child(3)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
175
+ assert_in list, "li:nth-child(4)", %{<a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a>}
176
+ assert_in list, "li:nth-child(5)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people/deep-section">Deep section</a></strong>}
177
+ end
178
+
149
179
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.3.3
5
+ version: 3.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-09-21 00:00:00 Z
14
+ date: 2012-09-24 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -152,7 +152,7 @@ dependencies:
152
152
  requirements:
153
153
  - - "="
154
154
  - !ruby/object:Gem::Version
155
- version: 1.9.2
155
+ version: 2.7.1
156
156
  type: :development
157
157
  prerelease: false
158
158
  version_requirements: *id013
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
239
  requirements:
240
240
  - - ">="
241
241
  - !ruby/object:Gem::Version
242
- hash: -600482071330210129
242
+ hash: -1283925911872711300
243
243
  segments:
244
244
  - 0
245
245
  version: "0"
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
248
  requirements:
249
249
  - - ">="
250
250
  - !ruby/object:Gem::Version
251
- hash: -600482071330210129
251
+ hash: -1283925911872711300
252
252
  segments:
253
253
  - 0
254
254
  version: "0"