summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--lib/rss/2.0.rb1
-rw-r--r--lib/rss/content.rb11
-rw-r--r--lib/rss/converter.rb24
-rw-r--r--lib/rss/dublincore.rb21
-rw-r--r--lib/rss/rss.rb28
-rw-r--r--lib/rss/syndication.rb46
-rw-r--r--test/rss/test_accessor.rb1
-rw-r--r--test/rss/test_content.rb2
-rw-r--r--test/rss/test_dublincore.rb2
-rw-r--r--test/rss/test_parser.rb1
-rw-r--r--test/rss/test_syndication.rb2
-rw-r--r--test/rss/test_trackback.rb2
13 files changed, 95 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 9e82e0b2341..bcc35dc7628 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Tue Feb 3 22:36:25 2004 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/2.0.rb, lib/rss/content.rb, lib/rss/dublincore.rb,
+ lib/rss/rss.rb, lib/rss/syndication.rb: removed warnings.
+
+ * lib/rss/converter.rb: removed handling load error of nkf.
+
+ * test/rss/test_syndication.rb, test/rss/test_trackback.rb,
+ test/rss/test_dublincore.rb, test/rss/test_content.rb: replaced
+ 'require "rss/parser"' by 'require "rss/1.0"'.
+
+ * test/rss/test_parser.rb, test/rss/test_accessor.rb: removed
+ 'require "rss/parser"'.
+
Tue Feb 3 11:23:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (reduce_nodes): remove tail returns. [ruby-talk:90934]
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
index fd6a242d21e..799e6b788f5 100644
--- a/lib/rss/2.0.rb
+++ b/lib/rss/2.0.rb
@@ -129,6 +129,7 @@ EOT
module ListenerMixin
private
+ alias start_rss09 start_rss
def start_rss(tag_name, prefix, attrs, ns)
check_ns(tag_name, prefix, ns, Rss::URI)
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index 3bb82f987c4..fae0b687be4 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -13,9 +13,13 @@ module RSS
ELEMENTS = []
- %w(encoded).each do |x|
- install_text_element("#{CONTENT_PREFIX}_#{x}")
- end
+ def self.included(mod)
+ mod.module_eval(<<-EOC)
+ %w(encoded).each do |x|
+ install_text_element("\#{CONTENT_PREFIX}_\#{x}")
+ end
+ EOC
+ end
def content_validate(tags)
counter = {}
@@ -38,6 +42,7 @@ module RSS
end
prefix_size = CONTENT_PREFIX.size + 1
+ ContentModel::ELEMENTS.uniq!
ContentModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], CONTENT_URI, "#{x}=")
end
diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb
index 144daab5641..4f00c86973d 100644
--- a/lib/rss/converter.rb
+++ b/lib/rss/converter.rb
@@ -111,44 +111,28 @@ EOC
end
def def_to_euc_jp_from_shift_jis
- begin
- require "nkf"
- rescue LoadError
- raise UnknownConversionMethodError.new('EUC-JP', 'Shift_JIS')
- end
+ require "nkf"
def_convert do |value|
"NKF.nkf('-Se', #{value})"
end
end
def def_to_shift_jis_from_euc_jp
- begin
- require "nkf"
- rescue LoadError
- raise UnknownConversionMethodError.new('Shift_JIS', 'EUC-JP')
- end
+ require "nkf"
def_convert do |value|
"NKF.nkf('-Es', #{value})"
end
end
def def_to_euc_jp_from_iso_2022_jp
- begin
- require "nkf"
- rescue LoadError
- raise UnknownConversionMethodError.new('EUC-JP', 'ISO-2022-JP')
- end
+ require "nkf"
def_convert do |value|
"NKF.nkf('-Je', #{value})"
end
end
def def_to_iso_2022_jp_from_euc_jp
- begin
- require "nkf"
- rescue LoadError
- raise UnknownConversionMethodError.new('ISO-2022-JP', 'EUC-JP')
- end
+ require "nkf"
def_convert do |value|
"NKF.nkf('-Ej', #{value})"
end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index c46ab76451f..18b5413a5cf 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -13,14 +13,18 @@ module RSS
ELEMENTS = []
- %w(title description creator subject publisher
- contributor type format identifier source
- language relation coverage rights).each do |x|
- install_text_element("#{DC_PREFIX}_#{x}")
- end
-
- %w(date).each do |x|
- install_date_element("#{DC_PREFIX}_#{x}", 'iso8601', x)
+ def self.included(mod)
+ mod.module_eval(<<-EOC)
+ %w(title description creator subject publisher
+ contributor type format identifier source
+ language relation coverage rights).each do |x|
+ install_text_element("\#{DC_PREFIX}_\#{x}")
+ end
+
+ %w(date).each do |x|
+ install_date_element("\#{DC_PREFIX}_\#{x}", 'iso8601', x)
+ end
+ EOC
end
def dc_validate(tags)
@@ -47,6 +51,7 @@ module RSS
end
prefix_size = DC_PREFIX.size + 1
+ DublincoreModel::ELEMENTS.uniq!
DublincoreModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 0acf7803e5a..2dfc0d1ecc7 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -92,6 +92,8 @@ module RSS
include Utils
def install_have_child_element(name)
+ add_need_initialize_variable(name)
+
attr_accessor name
install_element(name) do |n, elem_name|
<<-EOC
@@ -106,8 +108,9 @@ EOC
alias_method(:install_have_attribute_element, :install_have_child_element)
def install_have_children_element(name, postfix="s")
- def_children_accessor(name, postfix)
add_have_children_element(name)
+
+ def_children_accessor(name, postfix)
install_element(name, postfix) do |n, elem_name|
<<-EOC
rv = ''
@@ -121,6 +124,8 @@ EOC
def install_text_element(name)
self::ELEMENTS << name
+ add_need_initialize_variable(name)
+
attr_writer name
convert_attr_reader name
install_element(name) do |n, elem_name|
@@ -144,6 +149,7 @@ EOC
def install_date_element(name, type, disp_name=name)
self::ELEMENTS << name
+ add_need_initialize_variable(name)
# accessor
convert_attr_reader name
@@ -323,6 +329,16 @@ EOC
@@have_children_elements << variable_name
end
+ @@need_initialize_variables = []
+
+ def self.add_need_initialize_variable(variable_name)
+ @@need_initialize_variables << variable_name
+ end
+
+ def self.need_initialize_variables
+ @@need_initialize_variables
+ end
+
EOC
end
@@ -346,8 +362,9 @@ EOC
attr_accessor :do_validate
def initialize(do_validate=true)
+ @converter = nil
@do_validate = do_validate
- initialize_have_children_elements
+ initialize_variables
end
def tag_name
@@ -371,6 +388,13 @@ EOC
end
private
+ def initialize_variables
+ self.class.need_initialize_variables.each do |variable_name|
+ instance_eval("@#{variable_name} = nil")
+ end
+ initialize_have_children_elements
+ end
+
def initialize_have_children_elements
self.class.have_children_elements.each do |variable_name|
instance_eval("@#{variable_name} = []")
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index 39005f64c8d..8f9ffb411fa 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -13,13 +13,31 @@ module RSS
ELEMENTS = []
- %w(updatePeriod updateFrequency).each do |x|
- install_text_element("#{SY_PREFIX}_#{x}")
- end
+ def self.included(mod)
+ mod.module_eval(<<-EOC)
+ %w(updatePeriod updateFrequency).each do |x|
+ install_text_element("\#{SY_PREFIX}_\#{x}")
+ end
- %w(updateBase).each do |x|
- install_date_element("#{SY_PREFIX}_#{x}", 'iso8601', x)
- end
+ %w(updateBase).each do |x|
+ install_date_element("\#{SY_PREFIX}_\#{x}", 'iso8601', x)
+ end
+
+ alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
+ def sy_updatePeriod=(new_value)
+ new_value = new_value.strip
+ validate_sy_updatePeriod(new_value) if @do_validate
+ self._sy_updatePeriod = new_value
+ end
+
+ alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
+ def sy_updateFrequency=(new_value)
+ new_value = new_value.strip
+ validate_sy_updateFrequency(new_value) if @do_validate
+ self._sy_updateFrequency = new_value.to_i
+ end
+ EOC
+ end
def sy_validate(tags)
counter = {}
@@ -35,21 +53,6 @@ module RSS
end
end
-
- alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
- def sy_updatePeriod=(new_value)
- new_value = new_value.strip
- validate_sy_updatePeriod(new_value) if @do_validate
- self._sy_updatePeriod = new_value
- end
-
- alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
- def sy_updateFrequency=(new_value)
- new_value = new_value.strip
- validate_sy_updateFrequency(new_value) if @do_validate
- self._sy_updateFrequency = new_value.to_i
- end
-
private
SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
def validate_sy_updatePeriod(value)
@@ -72,6 +75,7 @@ module RSS
end
prefix_size = SY_PREFIX.size + 1
+ SyndicationModel::ELEMENTS.uniq!
SyndicationModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=")
end
diff --git a/test/rss/test_accessor.rb b/test/rss/test_accessor.rb
index 4163ff9f1a0..b7dcb80226a 100644
--- a/test/rss/test_accessor.rb
+++ b/test/rss/test_accessor.rb
@@ -1,7 +1,6 @@
# -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
-require "rss/parser"
require "rss/1.0"
require "rss/2.0"
require "common"
diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb
index 46a679bdc10..b0872500365 100644
--- a/test/rss/test_content.rb
+++ b/test/rss/test_content.rb
@@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib"
require "rexml/document"
-require "rss/parser"
+require "rss/1.0"
require "rss/content"
require "common"
diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb
index b360ee9ca55..16c458f5370 100644
--- a/test/rss/test_dublincore.rb
+++ b/test/rss/test_dublincore.rb
@@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib"
require "rexml/document"
-require "rss/parser"
+require "rss/1.0"
require "rss/dublincore"
require "common"
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index cc0263b21ab..6ad5e380c40 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -1,7 +1,6 @@
# -*- tab-width: 2 -*- vim: ts=2
require "test/unit"
-require "rss/parser"
require "rss/1.0"
require "common"
diff --git a/test/rss/test_syndication.rb b/test/rss/test_syndication.rb
index 80659e1e69e..1eb62e052be 100644
--- a/test/rss/test_syndication.rb
+++ b/test/rss/test_syndication.rb
@@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib"
require "rexml/document"
-require "rss/parser"
+require "rss/1.0"
require "rss/syndication"
require "common"
diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb
index cd37b70b8be..85ab533617f 100644
--- a/test/rss/test_trackback.rb
+++ b/test/rss/test_trackback.rb
@@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib"
require "rexml/document"
-require "rss/parser"
+require "rss/1.0"
require "rss/trackback"
require "common"