[nanoc] here is an interesting issue for you: multipart document & layout

69 views
Skip to first unread message

Ollivier Robert

unread,
Apr 9, 2013, 6:25:25 PM4/9/13
to nanoc
Hello everyone,

I have a long page in Markdown that I want to split up into
several .md files and would like nanoc to reassemble/compile all these
into a single .html file. I have the 'default' layout and a partial
layout called 'listitem'. At the root of the article, the .md loads
all compiled children into itself for rendering. The interesting part
is that, every individually rendered part is correctly generated with
the list item layout but when gathered into a single .html page, part
of the formatting in the partial layout is lost :(

The site is my own personal one: http://www.keltia.net/ so it is very
easy to see the result.

All code is at http://bitbucket.org/keltia/keltia.net (or
http://assets.keltia.net/keltia.tar.xz) but the interesting parts are:

filesystem:
-=-=-
content/about:
cameras/
cameras.md

content/about/cameras:
part1.md
part10.md
part11.md
part12.md
part2.md
part3.md
part4.md
part5.md
part6.md
part7.md
part8.md
part9.md
-=-=-

cameras.md:
-=-=-
---
title: My [long] list of cameras overtime
short_name: List of cameras
image: pentax-k-5.png
is_dynamic: true
---

## <%= @item[:title] %>

Here is a rather long history of my cameras and lenses...

<% @item.children.sort_by{|i| i[:slug].to_i}.each do |item| %>
<%= item.compiled_content %>
<% end %>
-=-=-

layout/listitem.html
-=-=-
<h3><%= @item[:title] %></h3>

<div class="left">
<img src="http://assets.keltia.net/images/<%= @item[:image] %>"
alt="<%= @item[:alt] %>" width="70"/>
</div>
<div class="main">
<%= yield %>
</div>
-=-=-

Expected result:
-=-=-
[...]
<h3>At the beginning</h3>

<div class="left">
<img src="http://assets.keltia.net/images/600si.png" alt="Minolta
600si Classic" width="70"/>
</div>
<div class="main">
<p>At the beginning, I had no camera on my own [...]
-=-=-

but in the final output/about/cameras/index.html there is only this,
layout seems to be lost. Why item.compiled_content empty??
-=-=-
<p>At the beginning, I had no camera on my own, [...]
-=-=-

Any idea? Thanks to bobthecow and darix who tried to help me on the
IRC channel :)

justin

unread,
Apr 10, 2013, 3:18:13 AM4/10/13
to na...@googlegroups.com
the #compiled_content method accepts a :snapshot option: http://nanoc.ws/docs/api/Nanoc/ItemRep.html#compiled_content-instance_method

By default, it uses the compiled content immediately before the first #layout call in your compile rule. If you don't want to use that, you can add your own snapshot and specify that one instead:

compile '*' do
  filter :kramdown
  layout 'wheee'
  snapshot :post_wheee
end

Then you can get the compiled content at that snapshot instead:

<%= someitem.compiled_content(:snapshot => :post_wheee) %>

Note that in this case you could use the built-in :last snapshot, as it would be exactly the same as :post_wheee ... so maybe that example would be more useful if you wanted to get at your compiled content after "wheee" but before some other filter or layout :)

--j



--
--
You received this message because you are subscribed to the nanoc discusssion group.

To post to this group, send email to na...@googlegroups.com
To unsubscribe from this group, send email to
nanoc+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nanoc?hl=en

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





--
http://justinhileman.com

Ollivier Robert

unread,
Apr 10, 2013, 3:32:37 AM4/10/13
to na...@googlegroups.com
On Wed, Apr 10, 2013 at 9:18 AM, justin <jus...@justinhileman.info> wrote:
Note that in this case you could use the built-in :last snapshot, as it would be exactly the same as :post_wheee ... so maybe that example would be more useful if you wanted to get at your compiled content after "wheee" but before some other filter or layout :)

Using :snapshot => :last fixed it, thanks!
--
Ollivier Robert -
Reply all
Reply to author
Forward
0 new messages