Format date

80 views
Skip to first unread message

Miguel Gonçalves

unread,
May 19, 2012, 2:13:33 PM5/19/12
to nanoc
Hi!

I am running nano 3.3.6 and I am quite enjoying the experience.

At the moment I am stuck and can't seem to find the problem...

In content/index.erb I have the following

<% (@site.sorted_articles[0, 100] || []).each do |post| %>
<h1><%= link_to(post[:title], relative_path_to(post.path)) %></h1>
<%= attribute_to_time(post[:created_at]).day %> de <%=
monthName(attribute_to_time(post[:created_at]).month) %> de <
%=attribute_to_time(post[:created_at]).year %>
<%= post.compiled_content %>
<% end %>

When using the same date formatting code in layout/posts.erb

<h1><%= @item[:title] %></h1>
<p class="created_at">
<%= attribute_to_time(@item[:created_at]).day %> de <%=
monthName(attribute_to_time(@item[:created_at]).month) %> de <%=
attribute_to_time(@item[:created_at]).year %>
</p>
<%= yield %>

I get an error during the compilation:


miguel@li462-8:~/miguelgoncalves$ nanoc
Loading site data...
Compiling site...
create [0.11s] output/procissao-ao-som-de-michel-telo/
index.html
create [0.01s] output/idolos-qualidade-vs-espectaculo/
index.html
create [0.00s] output/este-queria-fazer-tt/index.html
create [0.01s] output/joyful-noise/index.html
create [0.01s] output/os-portuguese-e-as-regras/index.html
create [0.01s] output/ipad-e-o-wordpress/index.html
create [0.01s] output/mais-uma-supresa-no-bgt/index.html

Captain! We’ve been hit!

=== MESSAGE:

NoMethodError: undefined method `day' for nil:NilClass

=== COMPILATION STACK:

- [item] /stylesheet/ (rep default)

The individual posts are created but suddenly it dies.

Can anyone help?

Cheers,
Miguel

Denis Defreyne

unread,
May 19, 2012, 2:58:51 PM5/19/12
to na...@googlegroups.com
Hi Miguel,

Since nanoc crashes when you are requesting the “day” of something that does not exist, I believe that you are trying to use the posts layout for the stylesheet (since it calls <%= attribute_to_time(@item[:created_at]).day %>). Would that be it?

Cheers,

Denis
> --
> 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

signature.asc

Miguel Gonçalves

unread,
May 19, 2012, 3:07:37 PM5/19/12
to na...@googlegroups.com, denis.d...@stoneship.org
Hi Denis!

Many thanks for helping me out!

I don't quite understand what you mean. Let me explain what I am trying to do

I have a layout for the posts that is located in layouts/post.html.erb:

--
<h1><%= @item[:title] %></h1>
<p class="created_at">
<%= @item[:created_at] %>
<%= attribute_to_time(@item[:created_at]).month %>
</p>
<%= yield %>
--

When I coded this I believed that since the first line is working the attribute_to_time should also.

What am I doing wrong?

Many thanks!

Cheers,
Miguel

Denis Defreyne

unread,
May 19, 2012, 3:13:44 PM5/19/12
to na...@googlegroups.com
Hi Miguel,

The stylesheet item (content/stylesheet.css probably) is using the “posts” layout, which is probably not what you want. This is defined in the Rules file, so make sure your Rules are set up in such a way that your stylesheet isn’t treated as a post. Feel free to share your Rules file if you want me to take a look at it.

Cheers

Denis
signature.asc

Miguel Gonçalves

unread,
May 19, 2012, 3:22:02 PM5/19/12
to na...@googlegroups.com, denis.defreyne
Hi Denis!

Many thanks!

That was really the problem!

You saved me a big headache :-)

compile '/stylesheet/' do
end

in the Rules file did it! Is this the proper way to do it?

Could you point me to a proper way to parse a flag defined in the metadata of the articles in order to show a list of featured articles on a sidebar?

BTW, thanks for creating nanoc! I am moving away from a bloated WP installation to fast nginx serving a nano generated web site.

Cheers,
Miguel

Denis Defreyne

unread,
May 27, 2012, 12:44:07 AM5/27/12
to na...@googlegroups.com
On 19 May 2012, at 21:22, Miguel Gonçalves wrote:

> compile '/stylesheet/' do
> end
>
> in the Rules file did it! Is this the proper way to do it?

Yes!

> Could you point me to a proper way to parse a flag defined in the metadata of the articles in order to show a list of featured articles on a sidebar?

Do you mean a flag to indicate an article is featured? If so, you can add this metadata:

is_features: true

and then you can find all featured items, like this:

@items.select { |i| i[:is_featured] }

and iterate over them in order to generate a HTML list!

Cheers,

Denis

signature.asc
Reply all
Reply to author
Forward
0 new messages