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