Skip to content
Browse files

merge revision(s) 26307:

	* lib/rss/maker/base.rb, test/rss/test_maker_0.9.rb:
	accept any time format in maker. [ruby-core:26923]


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@27915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 0df6dfb commit b20ec139f562897f62cde3c12611357b097923c4 @shyouhei shyouhei committed May 20, 2010
Showing with 65 additions and 6 deletions.
  1. +5 −0 ChangeLog
  2. +42 −5 lib/rss/maker/base.rb
  3. +17 −0 test/rss/test_maker_0.9.rb
  4. +1 −1 version.h
View
5 ChangeLog
@@ -1,3 +1,8 @@
+Thu May 20 15:59:14 2010 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/maker/base.rb, test/rss/test_maker_0.9.rb:
+ accept any time format in maker. [ruby-core:26923]
+
Thu May 20 15:54:08 2010 Akinori MUSHA <knu@iDaemons.org>
* eval.c (recursive_push): Taint internal hash to prevent
View
47 lib/rss/maker/base.rb
@@ -341,7 +341,7 @@ def _set_default_values(&block)
:date => date,
:dc_dates => dc_dates.to_a.dup,
}
- _date = date
+ _date = _parse_date_if_needed(date)
if _date and !dc_dates.any? {|dc_date| dc_date.value == _date}
dc_date = self.class::DublinCoreDates::DublinCoreDate.new(self)
dc_date.value = _date.dup
@@ -353,6 +353,11 @@ def _set_default_values(&block)
date = keep[:date]
dc_dates.replace(keep[:dc_dates])
end
+
+ def _parse_date_if_needed(date_value)
+ date_value = Time.parse(date_value) if date_value.is_a?(String)
+ date_value
+ end
end
class RSSBase < Base
@@ -472,12 +477,24 @@ class ChannelBase < Base
end
%w(id about language
- managingEditor webMaster rating docs date
- lastBuildDate ttl).each do |element|
+ managingEditor webMaster rating docs ttl).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+ %w(date lastBuildDate).each do |date_element|
+ attr_reader date_element
+ add_need_initialize_variable(date_element)
+ end
+
+ def date=(_date)
+ @date = _parse_date_if_needed(_date)
+ end
+
+ def lastBuildDate=(_date)
+ @lastBuildDate = _parse_date_if_needed(_date)
+ end
+
def pubDate
date
end
@@ -672,11 +689,20 @@ class ItemBase < Base
def_classed_elements(name, attribute)
end
- %w(date comments id published).each do |element|
+ %w(comments id published).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
+ %w(date).each do |date_element|
+ attr_reader date_element
+ add_need_initialize_variable(date_element)
+ end
+
+ def date=(_date)
+ @date = _parse_date_if_needed(_date)
+ end
+
def pubDate
date
end
@@ -725,6 +751,8 @@ class EnclosureBase < Base
end
class SourceBase < Base
+ include SetupDefaultDate
+
%w(authors categories contributors generator icon
logo rights subtitle title).each do |name|
def_classed_element(name)
@@ -736,14 +764,23 @@ class SourceBase < Base
def_classed_elements(name, attribute)
end
- %w(id content date).each do |element|
+ %w(id content).each do |element|
attr_accessor element
add_need_initialize_variable(element)
end
alias_method(:url, :link)
alias_method(:url=, :link=)
+ %w(date).each do |date_element|
+ attr_reader date_element
+ add_need_initialize_variable(date_element)
+ end
+
+ def date=(_date)
+ @date = _parse_date_if_needed(_date)
+ end
+
def updated
date
end
View
17 test/rss/test_maker_0.9.rb
@@ -434,5 +434,22 @@ def test_not_valid_textInput
end
assert_nil(rss.channel.textInput)
end
+
+ def test_date_in_string
+ date = Time.now
+
+ rss = RSS::Maker.make("0.91") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_image(maker)
+
+ maker.items.new_item do |item|
+ item.title = "The first item"
+ item.link = "http://example.com/blog/1.html"
+ item.date = date.rfc822
+ end
+ end
+
+ assert_equal(date.iso8601, rss.items[0].date.iso8601)
+ end
end
end
View
2 version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2010-05-20"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20100520
-#define RUBY_PATCHLEVEL 256
+#define RUBY_PATCHLEVEL 257
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8

0 comments on commit b20ec13

Please sign in to comment.
Something went wrong with that request. Please try again.