module RailsConnector # This module contains helpers that can be used to build all kinds of menus. # @api public module MenuHelper include DisplayHelper # The build_menu method should serve as an example of how to build navigational # menus using Infopark Rails Connector. If you need to extend this method, copy it into # the relevant helper for your application. # # Example 1 - Single-tier menu: # # build_menu(Obj.find(123), nil, :id => "menu") # # produces: # # # # build_menu also takes a block so you can use it recursively for multiple levels # (current_page returns the Obj for "Insurance" in this example): # # Example 2 - Two-tier Menu: # # build_menu(Obj.find(123), current_page, :id => "main_menu") do |entry| # build_menu(entry, current_page, :id => "sub_menu") # end # # produces: # # # # @api public def build_menu(start_obj, current_obj, html_options, &block) children = table_of_contents(start_obj) content_tag(:ul, html_options) do content = "".html_safe children.each do |child| content << content_tag(:li) do list_entry = link_to(child.display_title, cms_path(child)) list_entry += block.call(child) if block_given? && current_obj && (current_obj == child || current_obj.ancestors.include?(child)) list_entry end end content end end end end