Question on implementing <r:time_ago_in_words/> and Radiant

I’d like to implement a time_ago_in_words tag so that I could write

<p">Posted by <r:author /> <r:time_ago_in_words /> ago</p>

and get

<p>Posted by Sean 5 days ago</p>

I figured since Rails already has a time_ago_in_words helper, I’d
just reuse it. But is the following a reasonable implementation? Does
it conform at all with “the Radiant way” of doing things?

this require bit feels a bit awkward

require ‘…/…/vendor/rails/actionpack/lib/action_view/helpers/
date_helper’

and so does this include

class Behavior::Base
include ActionView::Helpers::DateHelper
end

class CantThinkOfAGoodNameForThisBehavior < Behavior::Base

register “Cant Think of a Good Name for This”

description %{
Adds a global time_ago_in_words tag, as often seen in blog
entries (“Posted by Jack 3 days ago”)
}

I want to use this tag anywhere soI’m using Base.define_tags,

but since I registered above, it’ll appear in the Behaviors drop

down,

which doesn’t seem cool . . .

Behavior::Base.define_tags do

 tag "time_ago_in_words" do |tag|
   date = tag.locals.page.published_at || tag.locals.page.created_at
   time_ago_in_words date
 end

end

end

Sean, try this.

class Behavior::Base
define_tags do
tag “time_ago_in_words” do |tag|
ActionView::Base.new.time_ago_in_words(tags.locals.page.created_at)
end
end
end

You could substitute published_at for created_at in that statement.

Cheers,

Sean C.
seancribbs.com

On Sep 7, 2006, at 12:33 AM, Sean C. wrote:

Remember that Radiant caching will give you some problems with
this… but seeing as the cache expires after 5 minutes, i don’t
think it will be much of an issue.

Bodhi