Re: Date tag oddness

Walter,

The <r:date> tag shows the published_at date (or created_at if the
page hasn’t been published yet).

There was a past conversation where some of us agreed that it would be
good if the <r:date> tag accepted another parameter besides “format”
to indicate which date to show (published_at, created_at or
updated_at).

I think it’s a good idea that this new parameter accept another value
as “now” so it can show the actual date and time. For example, in a
site I’m working on I had to create a tag to do just that, but it wold
be a lot better to have this a standard feature.

Is anyone working on it?

Be Radiant!
Gabriel

On Mar 21, 2007, at 1:39 PM, Gabriel L. wrote:

Is anyone working on it?

Be Radiant!
Gabriel

I couldn’t figure out how to do exactly this, as my Ruby-fu is very
very young. So I simply defined a new tag called now, as a clone of
date:

desc %{
Renders the current date. The format attribute
uses the same formating codes used by the Ruby @strftime@ function.
By
default it’s set to @%A, %B %d, %Y@.

 *Usage:*
 <pre><code><r:now [format="format_string"] /></code></pre>

}
tag ‘now’ do |tag|
page = tag.locals.page
format = (tag.attr[‘format’] || ‘%A, %B %d, %Y’)
if date = Time.now
date.strftime(format)
end
end

SInce I used both Copy and Paste, I presume this violates DRY all over
the place. I’m still learning, and this works for now, but I’d love to
see how you would create a :now symbol and pass it to r:date.

Walter