How to write rules specific to item metadata?

5 views
Skip to first unread message

Pradeep Kumar

unread,
Oct 28, 2009, 12:15:45 AM10/28/09
to na...@googlegroups.com
Hi,

I think I have this question as I am a ruby newbie.

I would like to know how to write Rules like

compile "*" where item.kind='article'

which will apply to all items with their kind set to 'article' in the metadata.


Thanks
Pradeep

tenable

unread,
Oct 28, 2009, 12:46:59 AM10/28/09
to nanoc
> I would like to know how to write Rules like
>
> compile "*" where item.kind='article'
>
> which will apply to all items with their kind set to 'article' in the metadata.

Hi Pradeep,

I'm new to Nanoc, but I think you're better off not using an item
attribute and instead putting your articles in a subfolder of /
content, such as /content/articles/

Then in your rules you would do something like:

compile 'articles/*' do

end

tenable

unread,
Oct 28, 2009, 1:33:37 AM10/28/09
to nanoc
But if you still want to use attributes, I imagine something like this
should do the trick:

compile '*' do
if @item[:kind] == 'article'

else

end
end

Denis Defreyne

unread,
Oct 28, 2009, 4:50:01 AM10/28/09
to na...@googlegroups.com

Hi,

This is the recommended approach, with one small change: it's not
"@item" but "item", so:

compile '*' do
if item[:kind] == 'article'
...
else
...
end
end

Regards,

Denis

--
Denis Defreyne
denis.d...@stoneship.org

Pradeep Kumar

unread,
Oct 28, 2009, 6:31:24 AM10/28/09
to na...@googlegroups.com
Thanks tenable and Denis for the solution.

@tenable, I was aware of the path based rule approach, but prefer to
keep these information in the metadata instead of paths used for
implying some meaning.
Reply all
Reply to author
Forward
0 new messages