nutmeg 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nutmeg/tag_tree_helper.rb +5 -5
- data/lib/nutmeg/version.rb +1 -1
- data/spec/tag_tree_helper_spec.rb +5 -0
- 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: d46add46ba66cdd0a75ef3f905581a56d19c52a9
|
4
|
+
data.tar.gz: 0a823d5a6a20be742c214bdf56cbf7ff5ae1e432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13453f13317042df4e4fdd803ec9377f7f218453b0eba8472958ed5f2008d26834f7fb7c6947bdb9291053c621f040ec1b56118730a2c26d065264840b1578cb
|
7
|
+
data.tar.gz: ab785e32e4ee8f80e4a111da75d3f8498d21c88a93eab0297dce37668523fb662cf45d6d742637f69db1bf667e948a19c6a458e2f51374dcdcb80b3cf395a448
|
@@ -6,8 +6,8 @@ module Nutmeg
|
|
6
6
|
@tree = tree
|
7
7
|
end
|
8
8
|
|
9
|
-
def print_html(tags_given)
|
10
|
-
[print_node(@tree.original, tags_given)].join("")
|
9
|
+
def print_html(tags_given, greedy = false)
|
10
|
+
[print_node(@tree.original, tags_given, greedy)].join("")
|
11
11
|
end
|
12
12
|
|
13
13
|
def node_html(node, active, leaf, content)
|
@@ -18,10 +18,10 @@ module Nutmeg
|
|
18
18
|
([""] + node.parentage.map{|p| p.content[:slug]}.reverse.reject{|n| n == "root"} + [node.content[:slug]]).join("/")
|
19
19
|
end
|
20
20
|
|
21
|
-
def print_node(node, tags_given)
|
21
|
+
def print_node(node, tags_given, greedy = false)
|
22
22
|
output = []
|
23
23
|
if render_node?(node,tags_given)
|
24
|
-
output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name)), node.is_leaf?, node.content[:slug])
|
24
|
+
output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name) || (greedy == true && tags_given.include?(node.content[:slug]))), node.is_leaf?, node.content[:slug])
|
25
25
|
end
|
26
26
|
|
27
27
|
if !traverse_node?(node, tags_given)
|
@@ -31,7 +31,7 @@ module Nutmeg
|
|
31
31
|
if node.has_children?
|
32
32
|
output << "<ul>"
|
33
33
|
node.children.each do |child|
|
34
|
-
output << print_node(child, tags_given)
|
34
|
+
output << print_node(child, tags_given, greedy)
|
35
35
|
end
|
36
36
|
output << "</ul>"
|
37
37
|
end
|
data/lib/nutmeg/version.rb
CHANGED
@@ -17,6 +17,11 @@ describe Nutmeg::TagTreeHelper do
|
|
17
17
|
expect(Nutmeg::TagTreeHelper.new(subtree).print_html(["men", "collections", "summer_2015"])).to eq("<ul><li class='level_1 active'> <a >men</a><ul><li class='level_2 active'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/men/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/men/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf active'> <a href='/north/men/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >women</a><ul><li class='level_2'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/women/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >events</a><ul><li class='level_2 leaf'> <a href='/north/events/lowlands_2014'>lowlands_2014</a></li><li class='level_2 leaf'> <a href='/north/events/sinterklaas_2014'>sinterklaas_2014</a></li></ul></li><li class='level_1'> <a >collaborations</a><ul><li class='level_2 leaf'> <a href='/north/collaborations/afro_jack'>afro_jack</a></li><li class='level_2 leaf'> <a href='/north/collaborations/pr_co'>pr_co</a></li></ul></li></ul>")
|
18
18
|
end
|
19
19
|
|
20
|
+
it "outputs html for subtree (greedy)" do
|
21
|
+
subtree = @tree_from_yaml.tree.subtree("north")
|
22
|
+
expect(Nutmeg::TagTreeHelper.new(subtree).print_html(["men", "collections"],true)).to eq("<ul><li class='level_1 active'> <a >men</a><ul><li class='level_2 active'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/men/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/men/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf'> <a href='/north/men/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >women</a><ul><li class='level_2 active'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/women/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >events</a><ul><li class='level_2 leaf'> <a href='/north/events/lowlands_2014'>lowlands_2014</a></li><li class='level_2 leaf'> <a href='/north/events/sinterklaas_2014'>sinterklaas_2014</a></li></ul></li><li class='level_1'> <a >collaborations</a><ul><li class='level_2 leaf'> <a href='/north/collaborations/afro_jack'>afro_jack</a></li><li class='level_2 leaf'> <a href='/north/collaborations/pr_co'>pr_co</a></li></ul></li></ul>")
|
23
|
+
end
|
24
|
+
|
20
25
|
|
21
26
|
end
|
22
27
|
end
|