module EffectiveMenusHelper def render_menu(menu, options = {}, &block) menu = Effective::Menu.find_by_title(menu) if menu.kind_of?(String) return "
".html_safe if !menu.present? if (effectively_editting? && EffectivePages.authorized?(controller, :edit, menu) rescue false) options[:menu_id] = menu.id form_for(menu, :url => '/') { |form| options[:form] = form } end menu_items = menu.menu_items if menu.new_record? menu_items = menu_items.to_a.sort! { |a, b| a.lft <=> b.lft } end if block_given? && options[:form].blank? render_menu_items(menu_items, options) { yield } else render_menu_items(menu_items, options) end # if options[:for_editor] #else # Rails.cache.fetch(menu) { render_menu_items(menu.menu_items, options) } #end end def render_menu_items(items, options = {}, &block) if options[:form].present? && options[:form].kind_of?(ActionView::Helpers::FormBuilder) == false raise 'Expecting ActionView::Helpers::FormBuilder object for :form => option' end html = '' if options[:form] html << " ' end end html.html_safe end private # This is where we actually build out an li item def render_menu_item(item, caret, options) html = "" url = ( if item.menuable.kind_of?(Effective::Page) effective_pages.page_path(item.menuable) elsif item.divider? nil elsif (item.special || '').end_with?('_path') self.send(item.special) rescue nil elsif item.url.present? item.url end ).presence || '#' classes = (item.classes || '').split(' ') classes << 'active' if EffectivePages.menu[:apply_active_class] && request.try(:fullpath) == url classes << 'divider' if item.divider? classes << 'dropdown' if item.dropdown? classes = classes.join(' ') if item.leaf? html << (classes.present? ? "