Added filter date_to_rfc822

According to the W3C RSS Feed Validator, feeds must format dates as described
on RFC-822 to be valid. Refer to their site to get more info:
http://feedvalidator.org/docs/error/InvalidRFC2822Date.html

I also added a couple of missing unit tests to the other date filters
This commit is contained in:
Rafael Rosa Fu 2013-03-27 02:19:56 -04:00
parent 58f64e8269
commit 186b68adb0
2 changed files with 31 additions and 0 deletions

View File

@ -56,6 +56,20 @@ module Jekyll
date.xmlschema
end
# Format a date according to RFC-822
#
# date - The Time to format.
#
# Examples
#
# date_to_rfc822(Time.now)
# # => "Sun, 24 Apr 2011 12:34:46 +0000"
#
# Returns the formatted String.
def date_to_rfc822(date)
date.rfc822
end
# XML escape a string for use. Replaces any special characters with
# appropriate HTML entity replacements.
#

View File

@ -13,6 +13,7 @@ class TestFilters < Test::Unit::TestCase
context "filters" do
setup do
@filter = JekyllFilter.new
@sample_time = Time.parse "2013-03-27T11:22:33+00:00"
end
should "textilize with simple string" do
@ -42,6 +43,22 @@ class TestFilters < Test::Unit::TestCase
assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"])
end
should "format a date with short format" do
assert_equal "27 Mar 2013", @filter.date_to_string(@sample_time)
end
should "format a date with long format" do
assert_equal "27 March 2013", @filter.date_to_long_string(@sample_time)
end
should "format a time with xmlschema" do
assert_equal "2013-03-27T11:22:33+00:00", @filter.date_to_xmlschema(@sample_time)
end
should "format a time according to RFC-822" do
assert_equal "Wed, 27 Mar 2013 11:22:33 +0000", @filter.date_to_rfc822(@sample_time)
end
should "escape xml with ampersands" do
assert_equal "AT&amp;T", @filter.xml_escape("AT&T")
assert_equal "&lt;code&gt;command &amp;lt;filename&amp;gt;&lt;/code&gt;", @filter.xml_escape("<code>command &lt;filename&gt;</code>")