class Gollum::DescendantTree::TreeRenderer
Public Class Methods
new()
click to toggle source
# File lib/gollum/descendant_tree/tree_renderer.rb, line 7 def initialize @previous_nest_index = 0 end
Public Instance Methods
render(tree)
click to toggle source
# File lib/gollum/descendant_tree/tree_renderer.rb, line 11 def render(tree) output = "<ul class='tree'>\n" tree.each do |page| output += nest_for(page) if page[:nest_index] != 0 output += "<li><a href='/#{page[:url_path]}'>#{page[:title].titleize}</a>" end output += "</ul></li>\n" output += "</ul>\n" output end
Private Instance Methods
nest_for(page)
click to toggle source
# File lib/gollum/descendant_tree/tree_renderer.rb, line 24 def nest_for(page) output = '' if page[:nest_index] == @previous_nest_index output += "</li>\n" elsif page[:nest_index] > @previous_nest_index output += "<ul>\n" else output += "</li></ul>\n" * (@previous_nest_index - page[:nest_index]) end @previous_nest_index = page[:nest_index] output end