Parent

Namespace

Class/Module Index [+]

Quicksearch

Webgen::Tag::Menu

Generates a menu that can be configured extensively.

Public Instance Methods

call(tag, body, context) click to toggle source

Generate the menu.

# File lib/webgen/tag/menu.rb, line 56
def call(tag, body, context)
  tree = specific_menu_tree_for(context.content_node)

  (context.dest_node.node_info[:tag_menu_menus] ||= {})[[@params.to_a.sort, context.content_node.alcn]] = (tree ? tree.to_lcn_list : nil)

  if !tree || tree.children.empty?
    ''
  elsif param('tag.menu.nested')
    create_output_nested(context, tree)
  else
    create_output_not_nested(context, tree)
  end
end

Protected Instance Methods

build_specific_menu_tree(content_node, menu_node, level = 1) click to toggle source

Build a menu tree for content_node from the tree menu_node.

# File lib/webgen/tag/menu.rb, line 107
def build_specific_menu_tree(content_node, menu_node, level = 1)
  if menu_node.nil?          || level > param('tag.menu.max_levels') + param('tag.menu.start_level') - 1          || ((level > param('tag.menu.min_levels') + param('tag.menu.start_level') - 1)               && (menu_node.node.level >= content_node.level                    || (param('tag.menu.show_current_subtree_only') && !content_node.in_subtree_of?(menu_node.node))
             )
        )          || (level == param('tag.menu.start_level') && !content_node.in_subtree_of?(menu_node.node))
    return nil
  end

  sub_menu_tree = MenuNode.new(nil, menu_node.node)
  menu_tree = MenuNode.new(nil, menu_node.node)
  menu_node.children.each do |child|
    next if param('tag.menu.used_nodes') == 'files' && !child.is_in_tree_of_files?
    menu_tree.children << (this_node = MenuNode.new(menu_tree, child.node))
    sub_node = child.children.length > 0 ? build_specific_menu_tree(content_node, child, level + 1) : nil
    sub_node.children.each {|n| this_node.children << n; sub_menu_tree.children << n} if sub_node
  end

  if level < param('tag.menu.start_level')
    sub_menu_tree
  else
    menu_tree
  end
end
create_menu_tree(node, parent, lang) click to toggle source

Create and return a menu tree if at least one node is in the menu or nil otherwise.

# File lib/webgen/tag/menu.rb, line 190
def create_menu_tree(node, parent, lang)
  menu_node = MenuNode.new(parent, node)

  node.children.select do |child|
    child.lang == lang || child.lang.nil? || child.is_directory?
  end.each do |child|
    sub_node = create_menu_tree(child, menu_node, lang)
    menu_node.children << sub_node unless sub_node.nil?
  end
  menu_node.is_in_tree_of_files = (!node.is_fragment? && node['in_menu']) || menu_node.children.any? {|c| c.is_in_tree_of_files?}

  menu_node.children.empty? ? (node['in_menu'] ? menu_node : nil) : menu_node
end
create_output_nested(context, tree, level = 1) click to toggle source

Create the nested HTML menu of the tree using the provided context.

# File lib/webgen/tag/menu.rb, line 136
def create_output_nested(context, tree, level = 1)
  out = "<ul>"
  tree.children.each do |child|
    menu = child.children.length > 0 ? create_output_nested(context, child, level + 1) : ''
    style, link = menu_item_details(context.dest_node, child.node, context.content_node.lang, level)

    out << "<li #{style}>#{link}"
    out << menu
    out << "</li>"
  end
  out << "</ul>"
  out
end
create_output_not_nested(context, tree, level = 1) click to toggle source

Create the not nested HTML menu of the tree using the provided context.

# File lib/webgen/tag/menu.rb, line 151
def create_output_not_nested(context, tree, level = 1)
  submenu = ''
  out = "<ul>"
  tree.children.each do |child|
    submenu << (child.children.length > 0 ? create_output_not_nested(context, child, level + 1) : '')
    style, link = menu_item_details(context.dest_node, child.node, context.content_node.lang, level)

    out << "<li #{style}>#{link}</li>"
  end
  out << "</ul>"
  out << submenu
  out
end
node_changed?(node) click to toggle source

Check if the menus for node have changed.

# File lib/webgen/tag/menu.rb, line 75
def node_changed?(node)
  return if !node.node_info[:tag_menu_menus]

  node.node_info[:tag_menu_menus].each do |(params, cn_alcn), cached_tree|
    cn = node.tree[cn_alcn]
    menu_tree = menu_tree_for_lang(cn.lang, cn.tree.root)

    set_params(params.to_hash)
    tree = build_specific_menu_tree(cn, menu_tree)
    tree_list = tree.to_lcn_list if tree
    set_params({})

    if (tree.nil? && !cached_tree.nil?) || (tree_list && tree_list != cached_tree) ||
        (tree_list && tree_list.flatten.any? do |alcn|
           (n = node.tree[alcn]) && (r = n.routing_node(cn.lang)) && r != node && r.meta_info_changed?
         end)
      node.flag(:dirty)
      break
    end
  end
end
specific_menu_tree_for(content_node) click to toggle source

Wrapper method for returning the specific menu tree for content_node.

# File lib/webgen/tag/menu.rb, line 98
def specific_menu_tree_for(content_node)
  tree = menu_tree_for_lang(content_node.lang, content_node.tree.root)
  if param('tag.menu.used_nodes') == 'fragments'
    @params['tag.menu.start_level'] = param('tag.menu.start_level') + content_node.level
  end
  build_specific_menu_tree(content_node, tree)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.