Forum: Radiant CMS New Date Tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0008835496da08071dd6ea2a6fdf66fe?d=identicon&s=25 Gabriel Lamounier (Guest)
on 2007-04-09 20:23
(Received via mailing list)
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@.

  *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
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-04-09 20:36
(Received via mailing list)
How about this:

tag 'date' do |tag|
  page = tag.locals.page
  format = (tag.attr['format'] || '%A, %B %d, %Y')
  which = tag.attr['which']
  if which
    if (which == 'now')
      date = Date::Time.now
    elsif ['published_at', 'created_at', 'updated_at'].include? which
      date = page[which]
    else
      raise TagError, "Invalid value for 'which' attribute."
    end
  else
    date = page.published_at || page.created_at
  end

  date.strftime(format)
end



Notice that I made sure it's a valid attribute, otherwise raising an
error.

If none of the core team has problems with this, I'll write some tests
and patch it into mental.

Sean
6ec6f77ea603dd75b3a7a7775b059e79?d=identicon&s=25 John W. Long (Guest)
on 2007-04-09 22:20
(Received via mailing list)
Sean Cribbs wrote:
> and patch it into mental.
I like this, but am not sure that "which" is the right name for this
attribute.

--
John Long
http://wiseheartdesign.com
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-04-09 22:25
(Received via mailing list)
select?  I'm up for suggestions.

Sean
4979d3640fe418c8fca4ff63d1d88107?d=identicon&s=25 derek | idea company (Guest)
on 2007-04-09 22:34
(Received via mailing list)
Hello creators and other users of Radiant, I am fairly new to Radiant
CMS and love it quite a bit.  I have a question about navigation.  I
would like to be able to paginate my posts (ie. display Prev 1 2 3 4 5
Next | Show All) and can't seem to figure that out.  I couldn't find
anything on the mailing list archive about it.  Is this something that
is possible?  I would assume so considering I can limit the amount of
Children a Parent will display.
Thanks guys.

Derek

Derek Kinsman
The Idea Company

New Media Designer

http://www.ideacompany.ca/
http://nincompoopery.ambitiouslemon.com/
http://boring.ambitiouslemon.com/
1.416.371.5652
A47e0a6beeb9d048ff054fc1c3a97418?d=identicon&s=25 Walter Davis (walterdavis)
on 2007-04-09 22:55
(Received via mailing list)
Is 'type' already used for something else?

Walter
75ceef25624b3e44943a3b7319ba9612?d=identicon&s=25 Chris Schumann (torgo)
on 2007-04-09 23:19
(Received via mailing list)
Yes. I think Rails uses it, so it's kind-of reserved.

Chris
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-04-10 00:15
(Received via mailing list)
No name collision, just not good practice.  Although "type" can invoke
the class of the current object, it doesn't necessarily have to.  Still,
I would shy away from it.  Here's some more suggestions:

field
column
pick
use

Sean
6ec6f77ea603dd75b3a7a7775b059e79?d=identicon&s=25 John W. Long (Guest)
on 2007-04-10 02:38
(Received via mailing list)
Sean Cribbs wrote:
> No name collision, just not good practice.  Although "type" can invoke
> the class of the current object, it doesn't necessarily have to.  Still,
> I would shy away from it.  Here's some more suggestions:
>
> field
> column
> pick
> use

How about "for"?

--
John Long
http://wiseheartdesign.com
6ec6f77ea603dd75b3a7a7775b059e79?d=identicon&s=25 John W. Long (Guest)
on 2007-04-10 02:43
(Received via mailing list)
derek | idea company wrote:
> Hello creators and other users of Radiant, I am fairly new to Radiant
> CMS and love it quite a bit.  I have a question about navigation.  I
> would like to be able to paginate my posts (ie. display Prev 1 2 3 4 5
> Next | Show All) and can't seem to figure that out.  I couldn't find
> anything on the mailing list archive about it.  Is this something that
> is possible?  I would assume so considering I can limit the amount of
> Children a Parent will display.

It could be done using an extension, but you can't do this out of the
box with Radiant.

--
John Long
http://wiseheartdesign.com
7f85ce9d3a9ef1e91534fa9e911fccb1?d=identicon&s=25 Adam Salter (Guest)
on 2007-04-10 05:26
(Received via mailing list)
date_type

<r:date date_type="updated_at" format="%B %d, %Y" />
or
<r:date date_type="now" />
6ff8c661da37df260bbaeed18925ceb7?d=identicon&s=25 Brian Gernhardt (Guest)
on 2007-04-10 15:45
(Received via mailing list)
On Apr 9, 2007, at 11:25 PM, Adam Salter wrote:

> date_type
>
> <r:date date_type="updated_at" format="%B %d, %Y" />

That seems horribly redundant and repetitious.  How about the more
DRY <r:date type="updated_at" />

~~ B
F0d821a746f93cece1240d52d3e2617f?d=identicon&s=25 Pierre-Charles David (Guest)
on 2007-04-10 16:11
(Received via mailing list)
2007/4/10, John W. Long <ng@johnwlong.com>:
> How about "for"?
How about "when" ?

<r:date when="updated_at" />

<r:date when="now" />
6ec6f77ea603dd75b3a7a7775b059e79?d=identicon&s=25 John W. Long (Guest)
on 2007-04-10 16:30
(Received via mailing list)
Pierre-Charles David wrote:
> How about "when" ?
>
> <r:date when="updated_at" />
>
> <r:date when="now" />

"when" works for me.

--
John Long
http://wiseheartdesign.com
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-04-10 17:04
(Received via mailing list)
This topic is locked and can not be replied to.