RefineryCMS menu_presenter gotcha(me)

61 views
Skip to first unread message

Chris Maxwell

unread,
May 17, 2013, 7:46:04 PM5/17/13
to boston-r...@googlegroups.com
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


Travis Briggs

unread,
May 17, 2013, 7:57:52 PM5/17/13
to boston-r...@googlegroups.com
I don't quite understand the way in which a RefineryCMS site is built/deployed, so I'm probably missing something here. Why can't you just edit the code in menu presenter?

My impression is that you would clone the Refinery Rails project and then customize it to your needs, maybe that's not the case.

Okay so let's imagine for an instance that you can't touch the original Refinery source, it's read-only (which sounds like something near what's going on). Okay, well if you can override _header.html.erb then you can replace it with one that's identical, but that calls CustomMenuPresenter, which is your own class that you made by copy/pasting the code of menu presenter.

I'm pretty sure I'm misunderstanding all of this, but maybe this helps?

-Travis




Chris


--
You received this message because you are subscribed to the Google Groups "Boston Ruby Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boston-rubygroup+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Chris Maxwell

unread,
May 17, 2013, 8:17:14 PM5/17/13
to boston-r...@googlegroups.com
I think I reached that point of the day where my brain isn't working! Thanks.=)  With refinery, and this is my first stab at it, you're able to override things by calling parts of the different engines into your application through a rake task. I can override other presenters, but for some reason with this one I keep on getting "Couldn't match any presenter files in any extensions like menu_presenter." My hope was that I was getting the path wrong.
To unsubscribe from this group and stop receiving emails from it, send an email to boston-rubygro...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Boston Ruby Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boston-rubygro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages