module NavigationHelper def has_side_column? if root_page? return false end second_level_children_count = site.menu.submenu(current_page_path.first).try(:size) if second_level_children_count.nil? false else second_level_children_count >= 1 end end def top_level_navigation_links haml do first = 'first' site.menu.each do |item| active = current_page_path.first == item.name ? 'active' : '' haml 'li.tab', :class => first do haml 'a.tab', I18n.t('pages.' + item.name), :href => menu_item_path(item), :class => active end first = '' end end end def side_column_navigation_links if menu = site.menu.submenu(current_page_path.first) haml do haml 'ul.nav.nav-tabs.nav-stacked' do display_menu(menu, 1) end end end end def act_as(page) page = site.find_page(page) @current_page_path = page.path render_page(page) end private def menu_item_path(item) "/#{I18n.locale}/#{item.path.join('/')}" end def display_menu(menu, level=0) menu.each do |item| haml 'li', :class => path_active(current_page_path, item) do haml 'a', I18n.t('pages.'+item.name), :href => menu_item_path(item), :class => "level#{level}" end display_menu(item.submenu, level+1) end end def path_active(page_path, menu_item) active = '' if menu_item.path == page_path active = 'active' elsif menu_item.path_prefix_of?(page_path) if menu_item.leaf_for_path?(page_path) active = 'active' else active = 'semi-active' end end active end def current_page_path @current_page_path ||= begin if @page @page.path elsif params[:page].is_a? String params[:page].split('/') else [] end end end # # the usage of 'home' as the default root page is hardcoded right now in the routes. # this should be changed in the future. # def root_page? @page && @page.path == ['home'] end end