devcenter-parser 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/devcenter-parser/header_id_generator.rb +1 -1
- data/lib/devcenter-parser/version.rb +1 -1
- data/test/header_id_generator_test.rb +46 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65f6956c4870415104ea82817a26a1985d4b71ec
|
4
|
+
data.tar.gz: 56c1b482c8c3cd46d470b4fda57a1940f3aa5592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee593eb72da41a4715f50e6531db7b698f41a5eb1cd7d4aee300c5e30bd09533e781562ebea25227b1cef6ec53d52fad1584de14abce3df322ac3542348be337
|
7
|
+
data.tar.gz: 2e62917baf949c6f63cef26f589ac91c6e9e155a2e44a8db52cfff79a58cf416ba4d9884b236616a7f344e3d6edc6910ad74cd35db5788d069921d9218507c62
|
@@ -47,7 +47,7 @@ class HeaderIdGenerator
|
|
47
47
|
def parent_header_nodes(node)
|
48
48
|
parent_tags(node.name).map do |parent_tag|
|
49
49
|
@header_nodes[0..@header_nodes.index(node)-1].select{ |sibling| sibling.name == parent_tag }.last
|
50
|
-
end
|
50
|
+
end.compact
|
51
51
|
end
|
52
52
|
|
53
53
|
# "h4" -> ["h2", "h3"]
|
@@ -22,40 +22,60 @@ describe 'HeaderIdGeneratorTest' do
|
|
22
22
|
|
23
23
|
|
24
24
|
describe 'ensures that there are not collisions between ids in subheaders' do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
describe 'by prepending the id of the previous headers as long as necessary' do
|
26
|
+
it 'when there are conflicts on headers from different sections' do
|
27
|
+
html = <<-HTML
|
28
|
+
<h2>A</h2>
|
29
|
+
<h3>B</h3>
|
30
|
+
<h4>Z</h4>
|
30
31
|
|
31
|
-
<h2>C</h2>
|
32
|
-
|
33
|
-
|
32
|
+
<h2>C</h2>
|
33
|
+
<h3>B</h3>
|
34
|
+
<h4>Z</h4>
|
35
|
+
HTML
|
36
|
+
result = result(html)
|
37
|
+
%w{ a c }.each{ |id| assert_id(result, 'h2', id) }
|
38
|
+
%w{ a-b c-b }.each{ |id| assert_id(result, 'h3', id) }
|
39
|
+
%w{ a-b-z c-b-z }.each{ |id| assert_id(result, 'h4', id) }
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
<h4>Z</h4>
|
42
|
+
it 'when there are conflicts on headers from different sections where some headers are missing' do
|
43
|
+
html = <<-HTML
|
44
|
+
<h2>A</h2>
|
45
|
+
<h4>Z</h4>
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
<h2>C</h2>
|
48
|
+
<h3>Z</h3>
|
49
|
+
HTML
|
50
|
+
result = result(html)
|
51
|
+
%w{ a c }.each{ |id| assert_id(result, 'h2', id) }
|
52
|
+
%w{ c-z }.each{ |id| assert_id(result, 'h3', id) }
|
53
|
+
%w{ a-z }.each{ |id| assert_id(result, 'h4', id) }
|
54
|
+
end
|
46
55
|
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
it 'when there are conflicts inside the same section' do
|
57
|
+
html = <<-HTML
|
58
|
+
<h2>D</h2>
|
59
|
+
<h3>X</h3>
|
60
|
+
<h4>Z</h4>
|
61
|
+
<h3>Y</h3>
|
62
|
+
<h4>Z</h4>
|
63
|
+
HTML
|
64
|
+
result = result(html)
|
65
|
+
%w{ d }.each{ |id| assert_id(result, 'h2', id) }
|
66
|
+
%w{ x y }.each{ |id| assert_id(result, 'h3', id) }
|
67
|
+
%w{ x-z y-z }.each{ |id| assert_id(result, 'h4', id) }
|
68
|
+
end
|
50
69
|
end
|
51
70
|
|
52
71
|
it 'by appending numbers for those subheaders with same nesting level and parent header name' do
|
53
72
|
html = <<-HTML
|
54
|
-
<h2>A</h2>
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
<h2>C</h2>
|
73
|
+
<h2>A</h2>
|
74
|
+
<h3>B</h3>
|
75
|
+
<h3>B</h3>
|
76
|
+
|
77
|
+
<h2>C</h2>
|
78
|
+
<h2>C</h2>
|
59
79
|
HTML
|
60
80
|
result = result(html)
|
61
81
|
%w{ a c-1 c-2 }.each{ |id| assert_id(result, 'h2', id) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devcenter-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heroku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: maruku
|