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.
Gabriel L. (Guest)
on 2007-04-09 22: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
Sean C. (Guest)
on 2007-04-09 22: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
John W. Long (Guest)
on 2007-04-10 00:20
(Received via mailing list)
Sean C. wrote:
> and patch it into mental.
I like this, but am not sure that "which" is the right name for this
attribute.

--
John L.
http://wiseheartdesign.com
Sean C. (Guest)
on 2007-04-10 00:25
(Received via mailing list)
select?  I'm up for suggestions.

Sean
derek | idea company (Guest)
on 2007-04-10 00: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
Walter D. (Guest)
on 2007-04-10 00:55
(Received via mailing list)
Is 'type' already used for something else?

Walter
Chris S. (Guest)
on 2007-04-10 01:19
(Received via mailing list)
Yes. I think Rails uses it, so it's kind-of reserved.

Chris
Sean C. (Guest)
on 2007-04-10 02: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
John W. Long (Guest)
on 2007-04-10 04:38
(Received via mailing list)
Sean C. 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 L.
http://wiseheartdesign.com
John W. Long (Guest)
on 2007-04-10 04: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 L.
http://wiseheartdesign.com
Adam S. (Guest)
on 2007-04-10 07:26
(Received via mailing list)
date_type

<r:date date_type="updated_at" format="%B %d, %Y" />
or
<r:date date_type="now" />
Brian G. (Guest)
on 2007-04-10 17:45
(Received via mailing list)
On Apr 9, 2007, at 11:25 PM, Adam S. 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
Pierre-Charles D. (Guest)
on 2007-04-10 18:11
(Received via mailing list)
2007/4/10, John W. Long <removed_email_address@domain.invalid>:
> How about "for"?
How about "when" ?

<r:date when="updated_at" />

<r:date when="now" />
John W. Long (Guest)
on 2007-04-10 18:30
(Received via mailing list)
Pierre-Charles D. wrote:
> How about "when" ?
>
> <r:date when="updated_at" />
>
> <r:date when="now" />

"when" works for me.

--
John L.
http://wiseheartdesign.com
Sean C. (Guest)
on 2007-04-10 19:04
(Received via mailing list)
This topic is locked and can not be replied to.