New Date Tag


#1

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:

}
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


#2

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


#3

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


#4

select? I’m up for suggestions.

Sean


#5

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


#6

Yes. I think Rails uses it, so it’s kind-of reserved.

Chris


#7

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


#8

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


#9

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


#10

date_type

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


#11

Is ‘type’ already used for something else?

Walter


#12

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


#13

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” />


#14

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


#15

http://dev.radiantcms.org/radiant/changeset/366