nutmeg 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa5c29f2a577c86a36fec11a3188fe85e4ae4133
4
- data.tar.gz: dcb623c140e4c6f936d7ca6a5cbd463fd5d2a657
3
+ metadata.gz: a5a48995ca11ced8e2a500ce801dd212aa5423b6
4
+ data.tar.gz: 71622c3200cf5ca25eb53792093fa3d1e9bf7ddb
5
5
  SHA512:
6
- metadata.gz: 1c75765380e498c42d16935e69fdd5a52b9a90809eafe76fab494141e8c89433e1875f193654b77cf58046fedb9a97158135ca376c3d194375189fc2fc9f9cf2
7
- data.tar.gz: 09ef6c8ed689511b0781d716178b299c8be55c00ad32d46c99d2cc00fde179120e520d7242591f73f70ae5ccb9252eb0a63d9306789d4f3752e0b88e4e171d9d
6
+ metadata.gz: 02b1843cf8865dfacc6512770db05c2aa3124f5756a473ebbcb7a40e80ad80823e0a2511d370a36906b1fc52d56c24aefc1d7b528bafe207679856cf8bee034b
7
+ data.tar.gz: bd08b2a0f9e09b1f6cc53f0852dfbf47abd1f7bda0553f51ae8097a1c9064e569c78fd430b0b7c12bcef341f627de02b2d88deb4b4c879b9f5f9c5a5d6f3e227
@@ -19,22 +19,23 @@ module Nutmeg
19
19
  node.content[:name] || node.content[:slug]
20
20
  end
21
21
 
22
- def print_html(tags_given, greedy = false)
23
- [print_node(@tree.original, tags_given, greedy)].join("")
22
+ def print_html(tags_given, greedy = false, extra_html = nil)
23
+ [print_node(@tree.original, tags_given, greedy, extra_html)].join("")
24
24
  end
25
25
 
26
- def node_html(node, active, leaf, content)
27
- "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{prepend_path}#{node_path(node)}#{append_path}\'" : ''}>#{content}</a>"
26
+ def node_html(node, active, leaf, content, extra_html = nil)
27
+ "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{prepend_path}#{node_path(node)}#{append_path}\'" : ''}>#{content}</a>#{extra_html && active && leaf ? extra_html : ''}"
28
28
  end
29
29
 
30
30
  def node_path(node)
31
31
  ([""] + node.parentage.map{|p| p.content[:slug]}.reverse.reject{|n| n == "root"} + [node.content[:slug]]).join("/")
32
32
  end
33
33
 
34
- def print_node(node, tags_given, greedy = false)
34
+ def print_node(node, tags_given, greedy = false, extra_html = nil)
35
35
  output = []
36
+
36
37
  if render_node?(node,tags_given)
37
- 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?, title(node))
38
+ 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?, title(node), extra_html)
38
39
  end
39
40
 
40
41
  if !traverse_node?(node, tags_given)
@@ -44,7 +45,7 @@ module Nutmeg
44
45
  if node.has_children?
45
46
  output << "<ul>"
46
47
  node.children.each do |child|
47
- output << print_node(child, tags_given, greedy)
48
+ output << print_node(child, tags_given, greedy,extra_html)
48
49
  end
49
50
  output << "</ul>"
50
51
  end
@@ -1,3 +1,3 @@
1
1
  module Nutmeg
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -28,6 +28,14 @@ describe Nutmeg::TagTreeHelper do
28
28
  subtree = @tree_from_json.tree
29
29
  expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["men", "collections"],false)).to eq("<ul><li class='level_1'> <a >North</a><ul><li class='level_2'> <a >Men</a><ul><li class='level_3 leaf'> <a href='/nl/t/north/men/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/north/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/north/women/footwear'>Footwear</a></li><li class='level_3'> <a >Eyewear</a><ul><li class='level_4 leaf'> <a href='/nl/t/north/women/eyewear/gfdgdfs'>gfdgdfs</a></li></ul></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/north/collaboration'>Collaboration</a></li></ul></li><li class='level_1'> <a >South</a><ul><li class='level_2'> <a >Men</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/men/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/women/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/eyewear'>Eyewear</a></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/south/collaboration'>Collaboration</a></li></ul></li></ul>")
30
30
  end
31
+ context "additional leaf content" do
32
+ it "renders additional content in the leaf" do
33
+ subtree = @tree_from_json.tree
34
+ expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["north", "men", "footwear"],false, "<a href='#'>Extra content</a>")).to eq("<ul><li class='level_1 active'> <a >North</a><ul><li class='level_2 active'> <a >Men</a><ul><li class='level_3 leaf active'> <a href='/nl/t/north/men/footwear'>Footwear</a><a href='#'>Extra content</a></li><li class='level_3 leaf'> <a href='/nl/t/north/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/north/women/footwear'>Footwear</a></li><li class='level_3'> <a >Eyewear</a><ul><li class='level_4 leaf'> <a href='/nl/t/north/women/eyewear/gfdgdfs'>gfdgdfs</a></li></ul></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/north/collaboration'>Collaboration</a></li></ul></li><li class='level_1'> <a >South</a><ul><li class='level_2'> <a >Men</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/men/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/women/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/eyewear'>Eyewear</a></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/south/collaboration'>Collaboration</a></li></ul></li></ul>")
35
+
36
+ end
37
+ end
31
38
  end
39
+
32
40
  end
33
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutmeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis van der Vliet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubytree