middleman-toc 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/middleman_toc/node.rb +0 -4
- data/lib/middleman_toc/toc.rb +48 -23
- data/lib/middleman_toc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bc1e2253bcba841a75573300dfd44ca6f57ef3d
|
4
|
+
data.tar.gz: 1430b8ff2d93597089a94f67d3a19e57a7016f11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c31e72f1652b99d8a5d7806b4e0236635e9e3b28cfd33c2d705738ec26847ae7ca54ece1d84c24fb7dcf0bf0e925cff4287b9660ac47e4d1c59c8effadab911
|
7
|
+
data.tar.gz: cf1e88729729b3b83fb04470176af715c78bd7c70a62a6bbdf14569757a87f0f4c6904778cab41677a39fa973d856cdac3669bf04e15d9224704e5ebbaf339ee
|
data/lib/middleman_toc/node.rb
CHANGED
data/lib/middleman_toc/toc.rb
CHANGED
@@ -15,37 +15,62 @@ module MiddlemanToc
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def prev_page(path)
|
18
|
-
node =
|
19
|
-
Tag.new(:a,
|
18
|
+
node = prev_node(path)
|
19
|
+
Tag.new(:a, 'Previous', class: 'prev', href: "/#{node.path}.html").render if node
|
20
20
|
end
|
21
21
|
|
22
22
|
def next_page(path)
|
23
|
-
node =
|
24
|
-
Tag.new(:a,
|
23
|
+
node = next_node(path)
|
24
|
+
Tag.new(:a, 'Next', class: 'next', href: "/#{node.path}.html").render if node
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
path.sub('.html', '')
|
29
|
-
end
|
27
|
+
private
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def normalize_path(path)
|
30
|
+
path.sub('.html', '')
|
31
|
+
end
|
32
|
+
|
33
|
+
def manifest
|
34
|
+
raise 'Could not load data/toc.yml' unless File.exists?('data/toc.yml')
|
35
|
+
normalize_nodes(YAML.load_file('data/toc.yml'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def nodes
|
39
|
+
@nodes ||= root.flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
def find(path)
|
43
|
+
nodes.detect { |node| node.path == path }
|
44
|
+
end
|
45
|
+
|
46
|
+
def index(path)
|
47
|
+
node = find(normalize_path(path))
|
48
|
+
nodes.index(node)
|
49
|
+
end
|
50
|
+
|
51
|
+
def prev_node(path)
|
52
|
+
ix = index(path)
|
53
|
+
nodes[ix - 1] if ix
|
54
|
+
end
|
55
|
+
|
56
|
+
def next_node(path)
|
57
|
+
ix = index(path)
|
58
|
+
nodes[ix + 1] if ix
|
59
|
+
end
|
35
60
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
61
|
+
def normalize_nodes(nodes)
|
62
|
+
Array(nodes).map do |node|
|
63
|
+
case node
|
64
|
+
when Array
|
65
|
+
normalize_nodes(node)
|
66
|
+
when String
|
67
|
+
{ 'path' => node }
|
68
|
+
when Hash
|
69
|
+
node.merge('children' => normalize_nodes(node['children']))
|
70
|
+
else
|
71
|
+
node
|
72
|
+
end
|
47
73
|
end
|
48
74
|
end
|
49
|
-
end
|
50
75
|
end
|
51
76
|
end
|