| Class | Tags::MenuTag |
| In: |
lib/webgen/plugins/tags/menu.rb
|
| Parent: | DefaultTag |
Generates a menu. All page files for which the meta information inMenu is set are used.
The order in which the menu items are listed can be controlled via the meta information orderInfo. By default the menu items are sorted by their titles.
# File lib/webgen/plugins/tags/menu.rb, line 70
70: def process_tag( tag, chain )
71: lang = chain.last['lang']
72: @menus ||= {}
73: unless @menus[lang]
74: @menus[lang] = create_menu_tree( Node.root( chain.last ), nil, lang )
75: @menus[lang].sort! if @menus[lang]
76: end
77:
78: style = @plugin_manager['MenuStyle/Default'].registered_handlers[param( 'menuStyle' )]
79: if style.nil?
80: log(:error) { "Invalid style specified in <#{chain.first.node_info[:src]}>" }
81: ''
82: elsif @menus[lang]
83: style.build_menu( chain.last, @menus[lang], param( 'options' ) )
84: else
85: ''
86: end
87: end
Returns a menu tree if at least one node is in the menu or nil otherwise.
# File lib/webgen/plugins/tags/menu.rb, line 95
95: def create_menu_tree( node, parent, lang )
96: menu_node = MenuNode.new( parent, node )
97: parent.del_child( menu_node ) if parent
98:
99: node.select do |child|
100: child['lang'] == lang || child['lang'].nil? || child.is_directory?
101: end.each do |child|
102: sub_node = create_menu_tree( child, menu_node, lang )
103: menu_node.add_child( sub_node ) unless sub_node.nil?
104: end if node.is_directory?
105:
106: return menu_node.has_children? ? menu_node : ( node['inMenu'] ? menu_node : nil )
107: end