Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Gollum
class Macro
class ListTree < Gollum::Macro
def render(tree_expr, heading_level = 3)
re = Regexp.new("^(" + tree_expr + ")\/");
subtree = {}
result = ''
if @wiki.pages.size > 0
@wiki.pages.each do |p|
m = re.match(p.path)
if m != nil
tree = m.to_a[1]
subpath = p.path.slice(tree.length+1, p.path.length-1)
if subpath.include?('/')
key = subpath.sub(/\/.+$/, '')
if !(subtree.has_key?(key))
subtree[key] = []
end
if !(p.path.sub(tree + '/' + key + '/', '').include?('/'))
subtree[key].push(p)
end
end
end
end
end
subtree.each { |path, pages|
result += "<h#{heading_level}>#{path}</h#{heading_level}>\n<ul>\n"
result += pages.map { |p|
if p.raw_data =~ /title\:/
page_title = p.metadata_title || p.name #Page.cname(p.name, '-', '-')
else
page_title = p.name
end
"<li><a class=\"internal present\" href=\"#{p.url_path}\">#{page_title}</a></li>\n"
}.join
result += "</ul>\n\n"
}
result
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment