I've been playing with nanoc and trying to get the automatic menu
generation to work. I've found some old posts on this group about this
(particularly http://groups.google.co.uk/group/nanoc/browse_thread/thread/da2ad380afefcf13).
However, these seem to have been written for nanoc2.
I've tried altering the suggested code, as it seems that @pages
doesn't exist anymore (at least the manual doesn't mention it), but
@items does exist. However, @items doesn't seem to have a .path
attribute, it seems that the only place a .path attribute comes is for
an ItemRep. So, I've tried modifying the code below to make it work,
but it still gives me an error saying "undefined method `path' for
<Nanoc3::Item:0x3fe42c82 identifier=/about/>:Nanoc3::Item".
The code I'm using is below:
<% home_page = @items.find { |i| i.rep[0].path == '/' } %>
<ul>
<li><%= link_to(home_page.title, home_page) %></li>
<% home_page.children.each do |page| %>
<li><%= link_to(page.title, page) %></li>
<% end %>
</ul>
I'm probably doing something rather silly, but I can't work out what
it is!
Cheers,
Robin
Hi,
nanoc 3.x has some major API changes compared to nanoc 2.x, which unfortunately leads to confusion when trying to use techniques for nanoc 2.x. Still, it’s usually not too hard to update the code for nanoc 3.x.
There are a few changes that you’ll need to perform:
* home_page.title should become home_page[:title]. Attributes (specified in the item metadata) are accessed using #[] now.
* link_to needs an item representation, not an item. An item rep corresponds to an output file in output/, so you need to link to a rep.
* To get a list of representations, use #reps, not #rep.
The updated code is this (I haven’t actually tried this code, but I’m fairly certain that it should work):
<% home_page = @items.find { |i| i.reps[0].path == '/' } %>
<ul>
<li><%= link_to(home_page[:title], home_page.reps[0]) %></li>
<% home_page.children.each do |page| %>
<li><%= link_to(page[:title], page.reps[0]) %></li>
<% end %>
</ul>
Hope this helps,
Denis
--
Denis Defreyne
denis.d...@stoneship.org
I'll shove this onto the Wiki on the menu help page, just to help
other people with the same problem.
Robin
On Dec 26, 12:31 pm, Denis Defreyne <denis.defre...@stoneship.org>
wrote:
> On 26 Dec 2009, at 13:19, Robin Wilson wrote:
>
>
>
> > Hi,
>
> > I've been playing with nanoc and trying to get the automatic menu
> > generation to work. I've found some old posts on this group about this
> > (particularlyhttp://groups.google.co.uk/group/nanoc/browse_thread/thread/da2ad380a...).
> I'll shove this onto the Wiki on the menu help page, just to help
> other people with the same problem.
Thanks! :)