Sha256: 52a5b417902dc7c0b9d101747c6a6773e2b939de057b1fd47c77320b358f53f8
Contents?: true
Size: 908 Bytes
Versions: 7
Compression:
Stored size: 908 Bytes
Contents
require 'titleize' module Gollum module DescendantTree class TreeRenderer def initialize @previous_nest_index = 0 end 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 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 end end end
Version data entries
7 entries across 7 versions & 1 rubygems