Sha256: f5fb5385ba0f26f791565cfc23fbbdfeb528d5d23ccb42eff6a30810ac41b78a
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
module Nutmeg class TagTreeHelper attr_accessor :tree def initialize(tree) raise "No valid data type" unless tree.class == TagTree @tree = tree end def print_html(tags_given) [print_node(@tree.original, tags_given)].join("") end def node_html(node, active, leaf, content) "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{node_path(node)}\'" : ''}>#{content}</a>" end def node_path(node) ([""] + node.parentage.map{|p| p.content[:slug]}.reverse.reject{|n| n == "root"} + [node.content[:slug]]).join("/") end def print_node(node, tags_given) output = [] if render_node?(node,tags_given) 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]) end if !traverse_node?(node, tags_given) output << "</li>" return output end if node.has_children? output << "<ul>" node.children.each do |child| output << print_node(child, tags_given) end output << "</ul>" end if render_node?(node,tags_given) output << "</li>" end output end def render_node?(node, tags_given) return false if node.is_root? traverse_node?(node, tags_given) end def traverse_node?(node, tags_given) true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nutmeg-0.0.5 | lib/nutmeg/tag_tree_helper.rb |