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>
<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
and so does this include
class CantThinkOfAGoodNameForThisBehavior < Behavior::Base
register “Cant Think of a Good Name for This”
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
which doesn’t seem cool . . .
tag "time_ago_in_words" do |tag| date = tag.locals.page.published_at || tag.locals.page.created_at time_ago_in_words date end