Skip to content

Instantly share code, notes, and snippets.

@Artforge
Created April 20, 2011 16:58
Show Gist options
  • Save Artforge/931912 to your computer and use it in GitHub Desktop.
Save Artforge/931912 to your computer and use it in GitHub Desktop.
Patch to add css class based on page title (in order to support background images)
<%
if menu_branch.title.nil?
css = "class='nil'"
elsif !!local_assigns[:apply_css] and (classes = css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count||=nil, collection, selected_item ||= nil)).any?
css = "class='#{menu_branch.title.underscore.gsub(" ","_")} #{classes.join(' ')}'"
else
css = "class='#{menu_branch.title.underscore.gsub(" ","_")}'"
end
dom_id = ("id='item_#{menu_branch_counter}'" if menu_branch.parent_id.nil? and menu_branch.title.present?)
hide_children = (defined?(hide_children) && hide_children)
children = if (hide_children || !menu_branch.has_descendants?)
[]
else
collection.select { |p| p.parent_id == menu_branch.id }
end
-%>
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '') %>>
<%= link_to menu_branch.url do %>
<div class="background"></div>
<span class="h5"><%= menu_branch.title %></span>
<% end %>
<% if children.present? -%>
<ul class='clearfix'>
<%=
render :partial => "/shared/menu_branch",
:collection => children,
:locals => {
:apply_css => local_assigns[:apply_css],
:hide_children => hide_children,
:collection => collection,
:selected_item => selected_item,
:sibling_count => children.size - 1
} -%>
</ul>
<% end -%>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment