Anyone ever work with RefineryCMS? I need help figuring something out.
I would like to add a distinct class to each menu <li> element generated
by Refinery. Menus are generated with this:
https://github.com/refinery/refinerycms/blob/master/pages/app/presenters/refinery/pages/menu_presenter.rb
Called here:
https://github.com/refinery/refinerycms/blob/master/core/app/views/refinery/_header.html.erb
In my application I can override _header.html.erb or the menu partial:
rake refinery:override view=_header
rake refinery:override view=**/*menu
... but I don't think I can override the menu_presenter. At least I
can't figure out how to. I've tried a dozen different "rake
refinery:override presenter=<stuff>" combinations to call it from its
murky depths and into my application with no success.
The reason I need to add a specific class to each list item in the
navigation -- based on the pages the CMS creates -- is because each
navigational element has a different icon. I've thought about using the
cycle helper, but I can't get at the <li> elements from the views I can
override:
_header.html.erb:
<%= link_to refinery.root_path, :class => 'logo ir' do %>
<h1><%= Refinery::Core.site_name %></h1>
<% end %>
<%= render(:partial => "/refinery/menu", :locals => {
:dom_id => 'menu',
:css => 'menu'
}) %>
_menu.html.erb:
<%
# Collect the root items.
# ::Refinery::Menu is smart enough to remember all of the items in
the original collection.
if (roots = local_assigns[:roots] || (collection ||=
refinery_menu_pages).roots).present?
dom_id ||= 'menu'
css = [(css || 'menu clearfix')].flatten.join(' ')
hide_children = Refinery::Core.menu_hide_children if hide_children.nil?
-%>
<nav id='<%= dom_id %>' class='<%= css %>' role='navigation'>
<ul>
<%= render :partial => '/refinery/menu_branch', :collection => roots,
:locals => {
:hide_children => hide_children,
:sibling_count => (roots.length - 1),
:menu_levels => local_assigns[:menu_levels],
:apply_css => true #if you don't care about
class='first' class='last' or class='selected' set apply_css to false
for speed.
} -%>
</ul>
</nav>
<% end -%>
For now I'll try using CSS's nth-child pseudo-selector, but there must
be a better way?
ul li:nth-child(1)
ul li:nth-child(2)
ul li:nth-child(3)
Etc.
(not well supported)
It's Friday night, so everyone is probably out and about, but if anyone
can lend a hand I'm stuck! Maybe I'm thinking about it all wrong and
need to go out and grab a beer=) ... but can't until I solve this.
Chris