[Radiant] New Date Tag

Gabriel Lamounier grezlam at gmail.com
Mon Apr 9 13:22:19 CDT 2007


Hi All,

I'm trying to code the new date tag we talked about earlier, but as
I'm new to ruby, I'm posting the code for you to have a look.

desc %{
  Renders the actual date or the date the page was published, created or updated
  (in the event that it has not been published yet, the date that it
was created).
  The format attribute uses the same formating codes used by the Ruby
@strftime@
  function. By default it's set to @%A, %B %d, %Y at .

  *Usage:*
  <pre><code><r:date [which="date_type"] [format="format_string"]
/></code></pre>
}
tag 'date' do |tag|
  page = tag.locals.page
  format = (tag.attr['format'] || '%A, %B %d, %Y')

  if tag.attr['which']
    if (tag.attr['which'] == 'now')
      date = Date::Time.now
    else
      which = tag.attr['which']   # are this two lines correct?
      date = page.which          # i don't know if it's the way to do it
    end
  else
    date = page.published_at || page.created_at
  end

  date.strftime(format)
end

date_type would be [created_at | published_at | updated_at | now]

I need some help

Thanks,
Gabriel



More information about the Radiant mailing list