class Nutmeg::TagTreeHelper

Attributes

tree[RW]

Public Class Methods

new(tree, options = {}) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 4
def initialize(tree, options = {})
  raise "No valid data type" unless tree.class == TagTree
  @options = options
  @tree = tree
end

Public Instance Methods

append_path() click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 14
def append_path
  @options[:append_path] || ""
end
intersectional_tags(tags_given) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 34
def intersectional_tags(tags_given)
  tree_nodes = []
  @tree.original.each do |node|
    if tags_given.include? node.content[:slug]
      tree_nodes << node
    end
  end
  return tree_nodes.uniq{|p| p.content[:slug]}
end
node_html(node, active, leaf, content, extra_html = nil) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 44
def node_html(node, active, leaf, content, extra_html = nil)
  "<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 : ''}"
end
node_path(node) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 48
def node_path(node)
  ([""] + node.parentage.map{|p| p.content[:slug]}.reverse.reject{|n| n == "root"} + [node.content[:slug]]).join("/")
end
prepend_path() click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 10
def prepend_path
  @options[:prepend_path] || ""
end
print_html(tags_given, greedy = false, extra_html = nil, do_not_wrap = false) click to toggle source
print_node(node, tags_given, greedy = false, extra_html = nil, do_not_wrap = false) click to toggle source
print_relevant_html(tags_given, greedy = false, extra_html = nil, do_not_wrap = false) click to toggle source
render_node?(node, tags_given) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 76
def render_node?(node, tags_given)
  return false if node.is_root?
  traverse_node?(node, tags_given)
end
title(node) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 18
def title(node)
  node.content[:name] || node.content[:slug]
end
traverse_node?(node, tags_given) click to toggle source
# File lib/nutmeg/tag_tree_helper.rb, line 81
def traverse_node?(node, tags_given)
  true
end