Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Fun with tags
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rob Emerson  
View profile  
 More options Sep 22 2008, 11:24 am
From: Rob Emerson <r...@remerson.plus.com>
Date: Mon, 22 Sep 2008 16:24:24 +0100
Local: Mon, Sep 22 2008 11:24 am
Subject: Fun with tags
Hi,

I'm still having a lot of trouble getting tags to working properly
within Nanoc 2.1. There has been a lot of really great work done on this
since earlier versions. However, it's still not quite at the point of
working "out of the box".. yet.

I'm working towards having tag index pages automatically generated. At
the moment, I'm trying to do this via a Rake task and prodding around
with the Nanoc API. Seems simple enough but I am missing something!

I took the basic skeleton for trawling tags out of my site via this
article here:

https://nanoc.stoneship.org/blog/2008-07-20/

And applied some modification to then inline compile the pages rather
than generating an intermediate tag page in content. That bit, I think
works fine. I also hacked it slightly to add a different layout
attribute for tags index pages and dumped this into a Rake task:

# Build pages for each tag
  tags_without_pages.each do |t|
    # Buid page
    puts t
    page = Nanoc::Page.new("Tag: #{t}", { :tags => t, :layout => "tag"

}, "/tags/#{t}")

    page.site = site
    page.build_reps
    pages << page
    site.compiler.run([page])
  end

But, and this is where I'm falling over, when attempting to compile the
page above I run into two key problems:

1) I can manage to generate an index page of pages titles only. If I try
to use any other attributes of the page, I get Nil problems all over the
place.

E.g. my regular front page "render-a-summary-of-the-last-few-articles"
ERB looks like this:

<% sorted_articles.last(5).each do |article| %>
    <div class="article">
        <h1 class="title"><%= article.page_id %></h1>
        <p class="date"><%= article.created_at.strftime("%A %d %B %Y")
%></p>    
        <p class="excerpt"><%= auto_excerpt(article) %>... <%= link_to
"read " + article.page_id, article.page_id %></p>
        <p class="tags">Tags: <%= tags_for(article, :base_url =>
'/tags/') %>.</p>
    </div>
<% end %>

This works fine. But if I try to do the same thing within a tags index
ERB template tags.erb I get:

<% pages_with_tag(@page.tags).each do |article| %>
    <div class="article">
        <h1 class="title"><%= article.page_id %></h1>  
        <p class="date"><%= article.created_at.strftime("%A %d %B %Y")
%></p>
        <p class="excerpt"><%= auto_excerpt(article) %>... <%= link_to
"read " + article.page_id, article.page_id %></p>        
        <p class="tags">Tags: <%= tags_for(article, :base_url =>
'/tags/') %>.</p>  
    </div>
<% end %>

I see compile errors of "can't covert Nil into String" which go away if
I remove references to page attributes other than "page_id" (which seems
to be the only attribute I can safely reference). i.e. there is
something different about the non-tags index articles somewhere...

So, what's the proper way to generate tag index pages?

2) A really annoying problem is also that my 'tags_for' links are all
now broken too when using the autocompiler.

E.g. say I have an article 'foo' that lives in
/output/articles/foo/index.html - I can link to this fine as
'/articles/foo/' via 'link_to' and Firefox follows it fine etc. all
works as it should.

But, if I try to do the same with my tags index pages, it doesn't work,
despite the <a href..> targets being identical:

<p class="excerpt"><a href="http://nanoc.stoneship.org/">Nanoc</a> in
itself is great for generating templatised static HTML pages. It's very
powerful and flexible with good built-in filter support and easy user...
<a href="/articles/nanoc-rake/">read Expanding the Power of Nanoc with
Rake</a></p>

<p class="tags">Tags: <a href="/tags/nanoc/">nanoc</a>, <a
href="/tags/rake/">rake</a>, <a href="/tags/sass/">sass</a>, <a
href="/tags/sitecopy/">sitecopy</a>.</p>

In the first line:

<a href="/articles/nanoc-rake/">read Expanding the Power of Nanoc with
Rake</a>

Links perfectly. Cool.

But, in the second line:

<a href="/tags/nanoc/">nanoc</a>

Gives a 404 when clicked on. If I instead type explicitly:
.../tags/nanoc/index.html  it works fine and the page loads.

Is this a bug in the autocompiler? In Firefox?!?

Many thanks in advance for any advice you can offer!

Rob


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Denis Defreyne  
View profile  
 More options Sep 22 2008, 12:09 pm
From: Denis Defreyne <denis.defre...@stoneship.org>
Date: Mon, 22 Sep 2008 18:09:00 +0200
Subject: Re: [nanoc] Fun with tags
On 22 Sep 2008, at 17:24, Rob Emerson wrote:

> 1) I can manage to generate an index page of pages titles only. If I  
> try
> to use any other attributes of the page, I get Nil problems all over  
> the
> place.

The issue here is that the @pages array when compiling a page with ERB  
is actually an array of page *proxies* (Nanoc::PageProxy). @page is a  
proxy as well, and so are @assets and @asset (Nanoc::AssetProxy).  
These proxies basically "rewrite" calls like "pageproxy.foo" to  
"page.attribute_named(:foo)".

So, when you're getting a list of pages or assets straight from a  
Nanoc::Site instance, you should know that these are actual  
Nanoc::Pages or Nanoc::Assets, and in order to get attributes off  
them, you need to use attribute_named(:something).

I would love nothing more than to simply get rid of proxies entirely.  
In retrospect, this was a bad design decision. Unfortunately, it's  
hard to revert this one; if I suddenly start passing Pages  (with an  
appropriate method_missing) instead of PageProxies around, then I risk  
getting backward compatibility issues.

This doesn't meant that it's impossible; it simply would require a lot  
of thought to make sure everything still works (fortunately nanoc has  
an extensive test case). It's definitely on my todo list! Possibly for  
2.2...

> 2) A really annoying problem is also that my 'tags_for' links are all
> now broken too when using the autocompiler. [..] But, in the second  
> line:

> <a href="/tags/nanoc/">nanoc</a>

> Gives a 404 when clicked on. If I instead type explicitly:
> .../tags/nanoc/index.html  it works fine and the page loads.

> Is this a bug in the autocompiler? In Firefox?!?

A bug in the autocompiler. When requesting a path for which no page  
exists (e.g. /tags/nanoc/), but which *does* contain an index filename  
(e.g. index.html), then the autocompiler should serve the index.html  
file.

This bug will be fixed soon. Thanks for letting me know! :)

Regards,

Denis

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Emerson  
View profile  
 More options Sep 22 2008, 2:26 pm
From: Rob Emerson <r...@remerson.plus.com>
Date: Mon, 22 Sep 2008 19:26:45 +0100
Local: Mon, Sep 22 2008 2:26 pm
Subject: Re: [nanoc] Re: Fun with tags
Thanks very much Denis - a fast and excellent reply as always!

Got it working now and it rocks.

I was just getting a bit confused between the Page and PageProxy objects
and that was catching me out.

I'll post some further notes on this in case other people are interested
or have a better approach.

Many thanks again! :)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Emerson  
View profile  
 More options Sep 24 2008, 11:26 am
From: Rob Emerson <r...@remerson.plus.com>
Date: Wed, 24 Sep 2008 16:26:22 +0100
Local: Wed, Sep 24 2008 11:26 am
Subject: Re: [nanoc] Re: Fun with tags
For anyone interested in this and how I've implemented it, you can find full details and code snippets here:

http://www.remerson.plus.com/articles/nanoc-tags/


Rob Emerson wrote:
Thanks very much Denis - a fast and excellent reply as always!

Got it working now and it rocks.

I was just getting a bit confused between the Page and PageProxy objects 
and that was catching me out.

I'll post some further notes on this in case other people are interested 
or have a better approach.

Many thanks again! :)

Denis Defreyne wrote:
  
On 22 Sep 2008, at 17:24, Rob Emerson wrote:

  
    
1) I can manage to generate an index page of pages titles only. If I  
try
to use any other attributes of the page, I get Nil problems all over  
the
place.
    
      
The issue here is that the @pages array when compiling a page with ERB  
is actually an array of page *proxies* (Nanoc::PageProxy). @page is a  
proxy as well, and so are @assets and @asset (Nanoc::AssetProxy).  
These proxies basically "rewrite" calls like "pageproxy.foo" to  
"page.attribute_named(:foo)".

So, when you're getting a list of pages or assets straight from a  
Nanoc::Site instance, you should know that these are actual  
Nanoc::Pages or Nanoc::Assets, and in order to get attributes off  
them, you need to use attribute_named(:something).

I would love nothing more than to simply get rid of proxies entirely.  
In retrospect, this was a bad design decision. Unfortunately, it's  
hard to revert this one; if I suddenly start passing Pages  (with an  
appropriate method_missing) instead of PageProxies around, then I risk  
getting backward compatibility issues.

This doesn't meant that it's impossible; it simply would require a lot  
of thought to make sure everything still works (fortunately nanoc has  
an extensive test case). It's definitely on my todo list! Possibly for  
2.2...

  
    
2) A really annoying problem is also that my 'tags_for' links are all
now broken too when using the autocompiler. [..] But, in the second  
line:

<a href="/tags/nanoc/">nanoc</a>

Gives a 404 when clicked on. If I instead type explicitly:
.../tags/nanoc/index.html  it works fine and the page loads.

Is this a bug in the autocompiler? In Firefox?!?
    
      
A bug in the autocompiler. When requesting a path for which no page  
exists (e.g. /tags/nanoc/), but which *does* contain an index filename  
(e.g. index.html), then the autocompiler should serve the index.html  
file.

This bug will be fixed soon. Thanks for letting me know! :)

Regards,

Denis

  
    



  


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Denis Defreyne  
View profile  
 More options Oct 1 2008, 10:42 am
From: Denis Defreyne <denis.defre...@stoneship.org>
Date: Wed, 1 Oct 2008 16:42:08 +0200
Local: Wed, Oct 1 2008 10:42 am
Subject: Re: [nanoc] Re: Fun with tags
On 24 Sep 2008, at 17:26, Rob Emerson wrote:

> For anyone interested in this and how I've implemented it, you can  
> find full details and code snippets here:

> http://www.remerson.plus.com/articles/nanoc-tags/

That's quite neat. I've added a link to that article on the nanoc Trac.

The original idea of generating placeholder tag pages is indeed much  
better than letting rake generate temporary pages and compile those.  
This is the technique I use for the archive pages for the nanoc site,  
but I'm not really liking it either, so I may actually change the way  
I create these archive pages some day.

By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a  
lowercase n. :)

Regards,

Denis

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Emerson  
View profile  
 More options Oct 2 2008, 3:53 pm
From: Rob Emerson <r...@remerson.plus.com>
Date: Thu, 02 Oct 2008 20:53:42 +0100
Local: Thurs, Oct 2 2008 3:53 pm
Subject: Re: [nanoc] Re: Fun with tags
Thanks Denis - feel free to rip off anything you want from it.

I'm happy with using placeholder pages for now - seems to work pretty well and I do like the fact it is explicit, so I can see nanoc updating the indices etc. when things change - gives me confidence it is actually working :)

> By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a  
> lowercase n. :)

Thanks - I'll go through and correct my articles :)


BTW: I have it on good authority from a friend of mine that the Sass asset fix works from the 2.1.3 release - many many thanks for the quick fix!

Cheers,

R

Denis Defreyne wrote:
On 24 Sep 2008, at 17:26, Rob Emerson wrote:

  
For anyone interested in this and how I've implemented it, you can  
find full details and code snippets here:

http://www.remerson.plus.com/articles/nanoc-tags/
    
That's quite neat. I've added a link to that article on the nanoc Trac.

The original idea of generating placeholder tag pages is indeed much  
better than letting rake generate temporary pages and compile those.  
This is the technique I use for the archive pages for the nanoc site,  
but I'm not really liking it either, so I may actually change the way  
I create these archive pages some day.

By the way, "nanoc" is spelled "nanoc" and not "Nanoc", i.e. a  
lowercase n. :)

Regards,

Denis

  


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google