slimmer 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,6 @@ module Slimmer
5
5
  meta_link = dest.at_css('meta[name="x-section-link"]')
6
6
  list = dest.at_css('nav[role=navigation] ol')
7
7
 
8
- # FIXME: Presumably this is meant to stop us adding a 'current section'
9
- # link if we're missing navigation, or x-section-* meta tags.
10
- # It doesn't work: #at_css will return a truthy object in any case.
11
8
  if meta_name && meta_link && list
12
9
  link_node = Nokogiri::XML::Node.new('a', dest)
13
10
  link_node['href'] = meta_link['content']
@@ -16,7 +13,7 @@ module Slimmer
16
13
  list_item = Nokogiri::XML::Node.new('li', dest)
17
14
  list_item.add_child(link_node)
18
15
 
19
- list.first_element_child.after(list_item)
16
+ list.add_child(list_item)
20
17
  end
21
18
  end
22
19
  end
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '1.2.2'
2
+ VERSION = '1.2.3'
3
3
  end
@@ -0,0 +1,105 @@
1
+ require_relative "../test_helper"
2
+
3
+ class SectionInserterTest < MiniTest::Unit::TestCase
4
+
5
+ # Note: the SectionInserter processor runs after the TagMover processor, so the meta
6
+ # tags have already been moved into the destination template
7
+
8
+ def test_should_add_section_link_to_breadcrumb
9
+ template = as_nokogiri %{
10
+ <html>
11
+ <head>
12
+ <meta content="Business" name="x-section-name">
13
+ <meta content="/browse/business" name="x-section-link">
14
+ </head>
15
+ <body>
16
+ <nav role="navigation">
17
+ <ol><li><a href="/">Home</a></li></ol>
18
+ </nav>
19
+ </body>
20
+ </html>
21
+ }
22
+
23
+ Slimmer::SectionInserter.new.filter(:any_source, template)
24
+ assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
25
+ assert_in template, "nav[role=navigation] ol li:nth-child(2)", %{<a href="/browse/business">Business</a>}
26
+ end
27
+
28
+ def test_should_add_section_link_after_last_item_in_breadcrumb
29
+ template = as_nokogiri %{
30
+ <html>
31
+ <head>
32
+ <meta content="Business" name="x-section-name">
33
+ <meta content="/browse/business" name="x-section-link">
34
+ </head>
35
+ <body>
36
+ <nav role="navigation">
37
+ <ol>
38
+ <li><a href="/">Home</a></li>
39
+ <li><a href="/browse">All Sections</a></li>
40
+ </ol>
41
+ </nav>
42
+ </body>
43
+ </html>
44
+ }
45
+
46
+ Slimmer::SectionInserter.new.filter(:any_source, template)
47
+ assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
48
+ assert_in template, "nav[role=navigation] ol li:nth-child(2)", %{<a href="/browse">All Sections</a>}
49
+ assert_in template, "nav[role=navigation] ol li:nth-child(3)", %{<a href="/browse/business">Business</a>}
50
+ end
51
+
52
+ def test_should_not_add_section_link_if_no_section_name_tag
53
+ template = as_nokogiri %{
54
+ <html>
55
+ <head>
56
+ <meta content="/browse/business" name="x-section-link">
57
+ </head>
58
+ <body>
59
+ <nav role="navigation">
60
+ <ol><li><a href="/">Home</a></li></ol>
61
+ </nav>
62
+ </body>
63
+ </html>
64
+ }
65
+
66
+ Slimmer::SectionInserter.new.filter(:any_source, template)
67
+ assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
68
+ assert_not_in template, "nav[role=navigation] ol li:nth-child(2)"
69
+ end
70
+
71
+ def test_should_not_add_section_link_if_no_section_link_tag
72
+ template = as_nokogiri %{
73
+ <html>
74
+ <head>
75
+ <meta content="Business" name="x-section-name">
76
+ </head>
77
+ <body>
78
+ <nav role="navigation">
79
+ <ol><li><a href="/">Home</a></li></ol>
80
+ </nav>
81
+ </body>
82
+ </html>
83
+ }
84
+
85
+ Slimmer::SectionInserter.new.filter(:any_source, template)
86
+ assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
87
+ assert_not_in template, "nav[role=navigation] ol li:nth-child(2)"
88
+ end
89
+
90
+ def test_should_do_nothing_if_navigation_not_in_template
91
+ template = as_nokogiri %{
92
+ <html>
93
+ <head>
94
+ <meta content="Business" name="x-section-name">
95
+ <meta content="/browse/business" name="x-section-link">
96
+ </head>
97
+ <body>
98
+ </body>
99
+ </html>
100
+ }
101
+
102
+ Slimmer::SectionInserter.new.filter(:any_source, template)
103
+ assert_not_in template, "nav[role=navigation]"
104
+ end
105
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.2
5
+ version: 1.2.3
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-08-13 00:00:00 Z
14
+ date: 2012-08-15 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -185,6 +185,7 @@ files:
185
185
  - lib/slimmer/test_template.rb
186
186
  - lib/slimmer.rb
187
187
  - Rakefile
188
+ - test/processors/section_inserter_test.rb
188
189
  - test/processors/header_context_inserter_test.rb
189
190
  - test/processors/body_inserter_test.rb
190
191
  - test/skin_test.rb
@@ -212,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
213
  requirements:
213
214
  - - ">="
214
215
  - !ruby/object:Gem::Version
215
- hash: -2032820947441079493
216
+ hash: -3770509032206210026
216
217
  segments:
217
218
  - 0
218
219
  version: "0"
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  requirements:
222
223
  - - ">="
223
224
  - !ruby/object:Gem::Version
224
- hash: -2032820947441079493
225
+ hash: -3770509032206210026
225
226
  segments:
226
227
  - 0
227
228
  version: "0"
@@ -233,6 +234,7 @@ signing_key:
233
234
  specification_version: 3
234
235
  summary: Thinner than the skinner
235
236
  test_files:
237
+ - test/processors/section_inserter_test.rb
236
238
  - test/processors/header_context_inserter_test.rb
237
239
  - test/processors/body_inserter_test.rb
238
240
  - test/skin_test.rb