Permalink
Browse files

Merge pull request #322 from SamWhited/rfc1123-date

Multiple Radius tags for rendering dates is redundant
  • Loading branch information...
2 parents f927223 + dac90ef commit 47097fab75af5753c3bd9b6b0035776529402cbe @saturnflyer saturnflyer committed Aug 27, 2012
@@ -30,5 +30,12 @@ module DeprecatedTags
keywords
end
end
+
+ deprecated_tag "rfc1123_date", :deadline => '2.0' do |tag|
+ page = tag.locals.page
+ if date = page.published_at || page.created_at
+ CGI.rfc1123_date(date.to_time)
+ end
+ end
-end
+end
@@ -747,10 +747,11 @@ class RequiredAttributeError < StandardError; end
desc %{
Renders the date based on the current page (by default when it was published or 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@. The @for@ attribute selects which date to render. Valid
- options are @published_at@, @created_at@, @updated_at@, and @now@. @now@ will render the
- current date/time, regardless of the page.
+ The format attribute uses the same formating codes used by the Ruby @strftime@ function.
+ By default it's set to @%A, %B %d, %Y@. You may also use the string @rfc1123@ as a shortcut
+ for @%a, %d %b %Y %H:%M:%S GMT@ (non-localized). The @for@ attribute selects which date to
+ render. Valid options are @published_at@, @created_at@, @updated_at@, and @now@. @now@ will
+ render the current date/time, regardless of the page.
*Usage:*
@@ -772,9 +773,14 @@ class RequiredAttributeError < StandardError; end
else
page.published_at || page.created_at
end
- @i18n_date_format_keys ||= (I18n.config.backend.send(:translations)[I18n.locale][:date][:formats].keys rescue [])
+ case format
+ when 'rfc1123'
+ CGI.rfc1123_date(date.to_time)
+ else
+ @i18n_date_format_keys ||= (I18n.config.backend.send(:translations)[I18n.locale][:date][:formats].keys rescue [])
format = @i18n_date_format_keys.include?(format.to_sym) ? format.to_sym : format
- I18n.l date, :format => format
+ I18n.l date, :format => format
+ end
end
desc %{
@@ -897,20 +903,6 @@ class RequiredAttributeError < StandardError; end
end
desc %{
- Outputs the published date using the format mandated by RFC 1123. (Ideal for RSS feeds.)
-
- *Usage:*
-
- <pre><code><r:rfc1123_date /></code></pre>
- }
- tag "rfc1123_date" do |tag|
- page = tag.locals.page
- if date = page.published_at || page.created_at
- CGI.rfc1123_date(date.to_time)
- end
- end
-
- desc %{
Renders a list of links specified in the @paths@ attribute according to three
states:
@@ -105,6 +105,12 @@
end
end
end
+
+ describe "<r:rfc1123_date>" do
+ it 'should render an RFC1123-compatible date' do
+ page(:dated).should render('<r:rfc1123_date />').as('Wed, 11 Jan 2006 00:00:00 GMT')
+ end
+ end
describe "<r:navigation>" do
it "should render with deprecated url attribute" do
@@ -121,4 +127,4 @@
end
end
end
-end
+end
@@ -613,6 +613,10 @@
page.should render('<r:date format="%d %b %Y" />').as('11 Jan 2006')
end
+ it "should render an RFC1123-compatible date if the 'format' attribute is set to 'rfc1123'" do
+ page.should render('<r:date format="rfc1123" />').as('Wed, 11 Jan 2006 00:00:00 GMT')
+ end
+
it "should format the published date according to localized format" do
page.should render('<r:date format="short" />').as(I18n.l(page.published_at, :format => :short))
end
@@ -822,10 +826,6 @@
page.should render('<r:escape_html><strong>a bold move</strong></r:escape_html>').as('&lt;strong&gt;a bold move&lt;/strong&gt;')
end
- it '<r:rfc1123_date> should render an RFC1123-compatible date' do
- page(:dated).should render('<r:rfc1123_date />').as('Wed, 11 Jan 2006 00:00:00 GMT')
- end
-
describe "<r:breadcrumbs>" do
it "should render a series of breadcrumb links separated by &gt;" do
expected = %{<a href="/">Home</a> &gt; <a href="/parent/">Parent</a> &gt; <a href="/parent/child/">Child</a> &gt; <a href="/parent/child/grandchild/">Grandchild</a> &gt; Great Grandchild}

0 comments on commit 47097fa

Please sign in to comment.