class Gollum::DescendantTree::TreeBuilder
Public Class Methods
new(wiki, name, dir)
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 5 def initialize (wiki, name, dir) @wiki = wiki @name = name @dir = dir @current_nest_index = 0 set_current_page_identifier end
Public Instance Methods
tree()
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 13 def tree page_descendants = [] @wiki.pages.each do |page| set_current_nest_index(page) if page.filename == @name if (is_descendant?(page)) page_descendants << { title: page.title, url_path: page.url_path, nest_index: get_current_index(page) } end end page_descendants end
Private Instance Methods
get_current_index(page)
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 44 def get_current_index(page) get_path_array(page).length - @current_nest_index end
get_path_array(page)
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 48 def get_path_array(page) return page.url_path.split('/') end
is_descendant?(page)
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 40 def is_descendant?(page) return true if page.url_path.include?(@current_page_identifier) end
set_current_nest_index(page)
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 36 def set_current_nest_index(page) @current_nest_index = get_path_array(page).length end
set_current_page_identifier()
click to toggle source
# File lib/gollum/descendant_tree/tree_builder.rb, line 31 def set_current_page_identifier current_page_name = @name.split('.').first @current_page_identifier = (@dir.length > 1) ? @dir + '/' + current_page_name : current_page_name end