class Jekyll::NestedMenuTag

Public Class Methods

new(tag_name, menu_root, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-nested-menu-generator.rb, line 5
def initialize(tag_name, menu_root, tokens)
  @menu_root = menu_root.strip
  super
end

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll-nested-menu-generator.rb, line 10
def render(context)
  menu(context)
end

Private Instance Methods

build_menu_hash(page, path_parts, menu_hash=nil) click to toggle source
# File lib/jekyll-nested-menu-generator.rb, line 33
def build_menu_hash(page, path_parts, menu_hash=nil)
  if path_parts.empty?
    return page
  end

  menu_hash = {} if menu_hash.nil?
  path_part = path_parts.shift

  menu_hash[path_part] = build_menu_hash(page, path_parts, menu_hash[path_part])

  menu_hash
end
build_menu_string(menu_hash) click to toggle source
# File lib/jekyll-nested-menu-generator.rb, line 46
def build_menu_string(menu_hash)
  menu_string = ''
  menu_hash.each do |dir_name, dir|
    item_string_part = ''

    # Separate the child pages from other descendent pages
    if dir.is_a?(Jekyll::Page)
      dir_hash = {}
      dir_hash[dir.name] = dir
      dir = dir_hash
    end
    pages = dir.select{ |k, v| v.is_a?(Jekyll::Page) }
    dir = dir.reject{ |k, v| v.is_a?(Jekyll::Page) } 

    pages.each do |file_name, page|
      item_string_part << "<a href='#{page.url}'>#{page.data['title'].split('/').last}</a>"
    end

    if not dir.empty?
      item_string_part << build_menu_string(dir)
    end

    menu_string << "<li>#{item_string_part}</li>"
  end
  "<ul>#{menu_string}</ul>"
end
menu(context) click to toggle source