Skip to content

Instantly share code, notes, and snippets.

@parndt
Created January 27, 2010 08:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/287664 to your computer and use it in GitHub Desktop.
Save parndt/287664 to your computer and use it in GitHub Desktop.
# /shared/_menu.html.erb
<% cache(:action_suffix => "site_menu") do %>
<ul id='<%= dom_id ||= "menu" %>' class='menu clearfix'>
<%= render :partial => "/shared/menu_branch", :collection => @menu_pages, :locals => {
:hide_children => RefinerySetting.find_or_set(:menu_hide_children, false)
} -%>
</ul>
<% end %>
# /shared/_menu_branch.html.erb
<%
css = []
css << "selected" if selected_page?(menu_branch) or descendant_page_selected?(menu_branch)
css << "first" if menu_branch_counter == 0
css << "last" if menu_branch_counter == menu_branch.shown_siblings.size
domid = "item_#{menu_branch_counter}" unless menu_branch.parent_id.present? or menu_branch.title.blank?
if menu_branch.in_menu?
-%>
<li<%= " class='#{css.join(' ')}'" unless css.blank? -%><%= " id='#{domid}'" unless domid.blank? -%>>
<%= link_to menu_branch.title, menu_branch.url %>
<% unless hide_children or menu_branch.parent_id.present? or (children = menu_branch.children.collect{|c| c if c.in_menu? }.compact).empty? %>
<ul class='clearfix'>
<%= render :partial => "/shared/menu_branch",
:collection => children,
:locals => {:hide_children => hide_children} -%>
</ul>
<% end %>
</li>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment