Dan Esparza
Dan Esparza

Reputation: 28375

Ruby / nanoc: How do I get a list of items to display in a page?

I fully admit I am a Ruby newb, and this question could come simply out of my ignorance for Ruby.

That being said, I'm getting started with the nanoc project (and loving it). I'd like to power my blog using this ... but: For the life of me, I can't figure out how to get a list of articles / posts to display on the main page. How do I do this?

I'd like to use erb/html if possible.

Upvotes: 3

Views: 1750

Answers (2)

Matti Pastell
Matti Pastell

Reputation: 9283

Here is some erb that creates a list of 10 most recent articles with the title, date and links. You can also add the article content using article.compiled_content. I use hpricot to display only the fist paragraph of each post in my blog

<% @site.sorted_articles[0, 10].each do |article| %>
<p><strong> 
<%= link_to(article[:title], article.path) %> </strong><br/>
<%= article[:created_at] %> <br/>
<%= tags_for(article) %> <br/></p>
<% end %>

Upvotes: 2

Koraktor
Koraktor

Reputation: 42913

In Nanoc3::Helpers::Blogging there are methods called articles and sorted_articles (see http://nanoc.stoneship.org/docs/api/3.1/Nanoc3/Helpers/Blogging.html).

You can "enable" that helper using

include Nanoc3::Helpers::Blogging

in a file in lib/ like lib/helpers.rb.

See http://nanoc.stoneship.org/docs/4-basic-concepts/#helpers

Upvotes: 1

Related Questions