summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog21
-rw-r--r--lib/rss/0.9.rb8
-rw-r--r--lib/rss/content.rb2
-rw-r--r--lib/rss/dublincore.rb2
-rw-r--r--lib/rss/maker/0.9.rb5
-rw-r--r--lib/rss/maker/2.0.rb2
-rw-r--r--lib/rss/maker/base.rb61
-rw-r--r--lib/rss/maker/content.rb12
-rw-r--r--lib/rss/maker/dublincore.rb38
-rw-r--r--lib/rss/maker/syndication.rb10
-rw-r--r--lib/rss/maker/trackback.rb12
-rw-r--r--lib/rss/rss.rb3
-rw-r--r--lib/rss/syndication.rb2
-rw-r--r--test/rss/test_1.0.rb2
-rw-r--r--test/rss/test_accessor.rb2
-rw-r--r--test/rss/test_content.rb2
-rw-r--r--test/rss/test_dublincore.rb2
-rw-r--r--test/rss/test_maker_0.9.rb4
-rw-r--r--test/rss/test_maker_1.0.rb4
-rw-r--r--test/rss/test_maker_2.0.rb3
-rw-r--r--test/rss/test_maker_xml-stylesheet.rb25
-rw-r--r--test/rss/test_parser.rb2
-rw-r--r--test/rss/test_syndication.rb2
-rw-r--r--test/rss/test_trackback.rb2
-rw-r--r--test/rss/test_xml-stylesheet.rb2
25 files changed, 146 insertions, 84 deletions
diff --git a/ChangeLog b/ChangeLog
index 7e1c6019dd4..a3fd99e15e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Wed Nov 3 15:38:28 2004 Kouhei Sutou <kou@cozmixng.org>
+
+ * test/rss/*.rb: removed tab width configuration headers.
+
+ * test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort.
+
+ * lib/rss/maker/*.rb: changed API to RSS version independence.
+
+ * lib/rss/maker/base.rb
+ (RSS::Maker::XMLStyleSheets::XMLStyleSheet): checked required
+ (pseudo) attributes.
+
+ * lib/rss/maker/base.rb (RSS::Maker::Items): sort -> do_sort.
+
+ * lib/rss/rss.rb (RSS::BaseModel.install_date_element): avoided
+ warning.
+
+ * lib/rss/0.9.rb (RSS::Rss#textinput): added convenience method.
+
Tue Nov 2 16:35:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/enumerator/enumerator.c (each_cons_i): pass copy of an
@@ -20,7 +39,7 @@ Tue Nov 2 01:20:09 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Mon Nov 1 22:25:56 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb: changed xml-stylesheet's API of RSS Maker
- like item's one.
+ like to item's one.
* lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#guess_type): fixed
regular expression bug.
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index d5c6b3a89d4..c772e80870d 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -51,6 +51,14 @@ module RSS
end
end
+ def textinput
+ if @channel
+ @channel.textInput
+ else
+ nil
+ end
+ end
+
def to_s(convert=true, indent=calc_indent)
next_indent = indent + INDENT
rv = <<-EOR
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index 4367d16d92d..280bbb8d6ba 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -16,7 +16,7 @@ module RSS
def self.append_features(klass)
super
- klass.module_eval(<<-EOC)
+ klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(encoded).each do |x|
install_text_element("\#{CONTENT_PREFIX}_\#{x}")
end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index 417ab5b179d..7ea9cf31dd3 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -16,7 +16,7 @@ module RSS
def self.append_features(klass)
super
- klass.module_eval(<<-EOC)
+ klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(title description creator subject publisher
contributor type format identifier source
language relation coverage rights).each do |x|
diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb
index 7223246647c..05578082b07 100644
--- a/lib/rss/maker/0.9.rb
+++ b/lib/rss/maker/0.9.rb
@@ -30,9 +30,6 @@ module RSS
class Channel < ChannelBase
- alias_method(:pubDate, :date)
- alias_method(:pubDate=, :date=)
-
def to_rss(rss)
channel = Rss::Channel.new
set = setup_values(channel)
@@ -150,7 +147,7 @@ module RSS
setup_other_elements(rss)
end
end
-
+
private
def have_required_values?
@title and @description and @name and @link
diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb
index 2fa61e80e66..05fc46480a0 100644
--- a/lib/rss/maker/2.0.rb
+++ b/lib/rss/maker/2.0.rb
@@ -48,8 +48,6 @@ module RSS
class Item < RSS09::Items::Item
- alias_method(:pubDate, :date)
-
def have_required_values?
@title or @description
end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index eb61f37ee26..21222351f28 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -16,26 +16,34 @@ module RSS
NEED_INITIALIZE_VARIABLES = []
def self.inherited(subclass)
- subclass.const_set("OTHER_ELEMENTS",
- OTHER_ELEMENTS.dup)
- subclass.const_set("NEED_INITIALIZE_VARIABLES",
- NEED_INITIALIZE_VARIABLES.dup)
+ subclass.const_set("OTHER_ELEMENTS", [])
+ subclass.const_set("NEED_INITIALIZE_VARIABLES", [])
+
+ subclass.module_eval(<<-EOEOC, __FILE__, __LINE__)
+ def self.other_elements
+ const_get("OTHER_ELEMENTS") + super
+ end
+
+ def self.need_initialize_variables
+ const_get("NEED_INITIALIZE_VARIABLES") + super
+ end
+ EOEOC
end
def self.add_other_element(variable_name)
const_get("OTHER_ELEMENTS") << variable_name
end
-
+
def self.other_elements
- const_get("OTHER_ELEMENTS")
+ OTHER_ELEMENTS
end
def self.add_need_initialize_variable(variable_name)
const_get("NEED_INITIALIZE_VARIABLES") << variable_name
end
-
+
def self.need_initialize_variables
- const_get("NEED_INITIALIZE_VARIABLES")
+ NEED_INITIALIZE_VARIABLES
end
EOC
end
@@ -84,10 +92,10 @@ module RSS
end
end
-
+
class RSSBase
include Base
-
+
class << self
def make(&block)
new.make(&block)
@@ -151,10 +159,12 @@ module RSS
class XMLStyleSheets
include Base
+ include Enumerable
extend Forwardable
def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last)
def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift)
+ def_delegators(:@xml_stylesheets, :each)
def initialize(maker)
super
@@ -183,11 +193,24 @@ module RSS
def to_rss(rss)
xss = ::RSS::XMLStyleSheet.new
+ guess_type_if_need(xss)
set = setup_values(xss)
if set
rss.xml_stylesheets << xss
end
end
+
+ def have_required_values?
+ @href and @type
+ end
+
+ private
+ def guess_type_if_need(xss)
+ if @type.nil?
+ xss.href = @href
+ @type = xss.type
+ end
+ end
end
end
@@ -204,6 +227,9 @@ module RSS
add_need_initialize_variable(element)
end
+ alias_method(:pubDate, :date)
+ alias_method(:pubDate=, :date=)
+
def initialize(maker)
super
@cloud = make_cloud
@@ -253,17 +279,19 @@ module RSS
class ItemsBase
include Base
+ include Enumerable
extend Forwardable
def_delegators(:@items, :<<, :[], :[]=, :first, :last)
def_delegators(:@items, :push, :pop, :shift, :unshift)
+ def_delegators(:@items, :each)
- attr_accessor :sort
+ attr_accessor :do_sort
def initialize(maker)
super
@items = []
- @sort = false
+ @do_sort = false
end
def normalize
@@ -282,11 +310,11 @@ module RSS
private
def sort_if_need
- if @sort.respond_to?(:call)
+ if @do_sort.respond_to?(:call)
@items.sort do |x, y|
- @sort.call(x, y)
+ @do_sort.call(x, y)
end
- elsif @sort
+ elsif @do_sort
@items.sort do |x, y|
y <=> x
end
@@ -318,6 +346,9 @@ EOC
add_need_initialize_variable(element)
end
+ alias_method(:pubDate, :date)
+ alias_method(:pubDate=, :date=)
+
def initialize(maker)
super
@guid = make_guid
diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb
index 67b237f4efd..96f3ccb6d9a 100644
--- a/lib/rss/maker/content.rb
+++ b/lib/rss/maker/content.rb
@@ -13,17 +13,17 @@ module RSS
klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current)
- current.#{element} = @#{element} if @#{element}
+ if #{element} and current.respond_to?(:#{element}=)
+ current.#{element} = @#{element} if @#{element}
+ end
end
-EOC
+ EOC
end
end
end
- class RSS10
- class Items
- class Item; include ContentModel; end
- end
+ class ItemsBase
+ class ItemBase; include ContentModel; end
end
end
end
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
index 6a4c64a464c..a9b8d587158 100644
--- a/lib/rss/maker/dublincore.rb
+++ b/lib/rss/maker/dublincore.rb
@@ -13,35 +13,35 @@ module RSS
klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current)
- current.#{element} = #{element} if #{element}
+ if #{element} and current.respond_to?(:#{element}=)
+ current.#{element} = #{element}
+ end
end
EOC
end
end
end
- class RSS10
- class Channel
- include DublinCoreModel
+ class ChannelBase
+ include DublinCoreModel
- alias_method(:_dc_date, :dc_date)
- alias_method(:_dc_date=, :dc_date=)
+ undef_method(:dc_date)
+ undef_method(:dc_date=)
+ alias_method(:dc_date, :date)
+ alias_method(:dc_date=, :date=)
+ end
+
+ class ImageBase; include DublinCoreModel; end
+ class ItemsBase
+ class ItemBase
+ include DublinCoreModel
+
+ undef_method(:dc_date)
+ undef_method(:dc_date=)
alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=)
end
-
- class Image; include DublinCoreModel; end
- class Items
- class Item
- include DublinCoreModel
-
- alias_method(:_dc_date, :dc_date)
- alias_method(:_dc_date=, :dc_date=)
- alias_method(:dc_date, :date)
- alias_method(:dc_date=, :date=)
- end
- end
- class Textinput; include DublinCoreModel; end
end
+ class TextinputBase; include DublinCoreModel; end
end
end
diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb
index ad846413ae6..72d00c63ead 100644
--- a/lib/rss/maker/syndication.rb
+++ b/lib/rss/maker/syndication.rb
@@ -13,15 +13,15 @@ module RSS
klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current)
- current.#{element} = @#{element} if @#{element}
+ if #{element} and current.respond_to?(:#{element}=)
+ current.#{element} = @#{element} if @#{element}
+ end
end
-EOC
+ EOC
end
end
end
- class RSS10
- class Channel; include SyndicationModel; end
- end
+ class ChannelBase; include SyndicationModel; end
end
end
diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb
index ff0e1abe444..1ec59ab0b0d 100644
--- a/lib/rss/maker/trackback.rb
+++ b/lib/rss/maker/trackback.rb
@@ -14,17 +14,17 @@ module RSS
klass.__send__(:attr_accessor, name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{name}(rss, current)
- current.#{name} = @#{name} if @#{name}
+ if #{name} and current.respond_to?(:#{name}=)
+ current.#{name} = @#{name} if @#{name}
+ end
end
-EOC
+ EOC
end
end
end
- class RSS10
- class Items
- class Item; include TrackBackModel; end
- end
+ class ItemsBase
+ class ItemBase; include TrackBackModel; end
end
end
end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 231fb1fb62a..b6afa24b934 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -4,6 +4,7 @@
# Author:: Kouhei Sutou <kou@cozmixng.org>
# Tutorial:: http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en
+
require "time"
class Time
@@ -234,7 +235,7 @@ EOC
# Is it need?
if @#{name}
class << @#{name}
- alias_method(:_to_s, :to_s) unless respond_to?(:_to_s)
+ undef_method(:to_s)
alias_method(:to_s, :#{type})
end
end
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index b8200ad70df..c274ff8c825 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -16,7 +16,7 @@ module RSS
def self.append_features(klass)
super
- klass.module_eval(<<-EOC)
+ klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(updatePeriod updateFrequency).each do |x|
install_text_element("\#{SY_PREFIX}_\#{x}")
end
diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb
index 43a168d035a..e6a81af2bd5 100644
--- a/test/rss/test_1.0.rb
+++ b/test/rss/test_1.0.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "rexml/document"
require "rss-testcase"
diff --git a/test/rss/test_accessor.rb b/test/rss/test_accessor.rb
index 1b92f9d98c8..5281a81c2ce 100644
--- a/test/rss/test_accessor.rb
+++ b/test/rss/test_accessor.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "rss-testcase"
require "rss/1.0"
diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb
index c0f6e4292f1..77cd1c7005d 100644
--- a/test/rss/test_content.rb
+++ b/test/rss/test_content.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "cgi"
require "rexml/document"
diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb
index 796666cdb57..d95d31f24e5 100644
--- a/test/rss/test_dublincore.rb
+++ b/test/rss/test_dublincore.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "cgi"
require "rexml/document"
diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb
index 4ccae45405d..df8cd5fe119 100644
--- a/test/rss/test_maker_0.9.rb
+++ b/test/rss/test_maker_0.9.rb
@@ -279,7 +279,7 @@ module RSS
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
end
- maker.items.sort
+ maker.items.do_sort = true
end
assert_equal(item_size, rss.items.size)
rss.channel.items.each_with_index do |item, i|
@@ -298,7 +298,7 @@ module RSS
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
end
- maker.items.sort = Proc.new do |x, y|
+ maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1]
end
end
diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb
index 91ba29d7116..8f80f6e2fe9 100644
--- a/test/rss/test_maker_1.0.rb
+++ b/test/rss/test_maker_1.0.rb
@@ -220,7 +220,7 @@ module RSS
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
end
- maker.items.sort = true
+ maker.items.do_sort = true
end
assert_equal(item_size, rss.items.size)
rss.items.each_with_index do |item, i|
@@ -239,7 +239,7 @@ module RSS
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
end
- maker.items.sort = Proc.new do |x, y|
+ maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1]
end
end
diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb
index 54375934c41..b0752f985f3 100644
--- a/test/rss/test_maker_2.0.rb
+++ b/test/rss/test_maker_2.0.rb
@@ -340,6 +340,7 @@ module RSS
item.comments = "#{comments}#{i}"
item.date = pubDate
end
+ maker.items.do_sort = true
end
assert_equal(item_size, rss.items.size)
rss.channel.items.each_with_index do |item, i|
@@ -363,7 +364,7 @@ module RSS
item.comments = "#{comments}#{i}"
item.date = pubDate
end
- maker.items.sort = Proc.new do |x, y|
+ maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1]
end
end
diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb
index b959073554e..bbdfdc682bc 100644
--- a/test/rss/test_maker_xml-stylesheet.rb
+++ b/test/rss/test_maker_xml-stylesheet.rb
@@ -5,7 +5,7 @@ require "rss/maker"
module RSS
class TestMakerXMLStyleSheet < TestCase
- def test_rss10
+ def test_xml_stylesheet
href = 'a.xsl'
type = 'text/xsl'
title = 'sample'
@@ -47,6 +47,29 @@ module RSS
assert_equal(href, xss.href)
assert_equal(type, xss.type)
end
+
+ def test_not_valid_xml_stylesheet
+ href = 'xss.XXX'
+ type = "text/xsl"
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ xss = maker.xml_stylesheets.new_xml_stylesheet
+ # xss.href = href
+ xss.type = type
+
+ setup_dummy_channel(maker)
+ end
+ assert(rss.xml_stylesheets.empty?)
+
+ rss = RSS::Maker.make("1.0") do |maker|
+ xss = maker.xml_stylesheets.new_xml_stylesheet
+ xss.href = href
+ # xss.type = type
+
+ setup_dummy_channel(maker)
+ end
+ assert(rss.xml_stylesheets.empty?)
+ end
end
end
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index 3fd26bffb4b..de4894997f0 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "rss-testcase"
require "rss/1.0"
diff --git a/test/rss/test_syndication.rb b/test/rss/test_syndication.rb
index 9d620089e12..a3dd763c837 100644
--- a/test/rss/test_syndication.rb
+++ b/test/rss/test_syndication.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "cgi"
require "rexml/document"
diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb
index 9c4b086caec..bfe39d005b5 100644
--- a/test/rss/test_trackback.rb
+++ b/test/rss/test_trackback.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "cgi"
require "rexml/document"
diff --git a/test/rss/test_xml-stylesheet.rb b/test/rss/test_xml-stylesheet.rb
index f3dee2c63bb..ab16d6e2ff3 100644
--- a/test/rss/test_xml-stylesheet.rb
+++ b/test/rss/test_xml-stylesheet.rb
@@ -1,5 +1,3 @@
-# -*- tab-width: 2 -*- vim: ts=2
-
require "rexml/document"
require "rss-testcase"