mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss/maker/base.rb, test/rss/test_maker_0.9.rb:
accept any time format in maker. [ruby-core:26923] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f6f3d1bc0e
commit
06dfb68d54
3 changed files with 64 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Jan 12 23:48:29 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]
|
||||
|
||||
Tue Jan 12 21:56:00 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* string.c (rb_str_set_len): call rb_str_modify.
|
||||
|
|
|
@ -358,7 +358,7 @@ module RSS
|
|||
: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
|
||||
|
@ -370,6 +370,11 @@ module RSS
|
|||
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
|
||||
|
||||
module SetupDefaultLanguage
|
||||
|
@ -503,12 +508,24 @@ module RSS
|
|||
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
|
||||
|
@ -703,11 +720,20 @@ module RSS
|
|||
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
|
||||
|
@ -764,6 +790,8 @@ module RSS
|
|||
end
|
||||
|
||||
class SourceBase < Base
|
||||
include SetupDefaultDate
|
||||
|
||||
%w(authors categories contributors generator icon
|
||||
logo rights subtitle title).each do |name|
|
||||
def_classed_element(name)
|
||||
|
@ -775,7 +803,7 @@ module RSS
|
|||
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
|
||||
|
@ -783,6 +811,15 @@ module RSS
|
|||
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
|
||||
|
|
|
@ -453,5 +453,22 @@ module RSS
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue