1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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"'.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2004-02-03 14:01:42 +00:00
parent 7376af3092
commit 1a235738a8
13 changed files with 94 additions and 59 deletions

View file

@ -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> Tue Feb 3 11:23:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (reduce_nodes): remove tail returns. [ruby-talk:90934] * parse.y (reduce_nodes): remove tail returns. [ruby-talk:90934]

View file

@ -129,6 +129,7 @@ EOT
module ListenerMixin module ListenerMixin
private private
alias start_rss09 start_rss
def start_rss(tag_name, prefix, attrs, ns) def start_rss(tag_name, prefix, attrs, ns)
check_ns(tag_name, prefix, ns, Rss::URI) check_ns(tag_name, prefix, ns, Rss::URI)

View file

@ -13,9 +13,13 @@ module RSS
ELEMENTS = [] ELEMENTS = []
%w(encoded).each do |x| def self.included(mod)
install_text_element("#{CONTENT_PREFIX}_#{x}") mod.module_eval(<<-EOC)
end %w(encoded).each do |x|
install_text_element("\#{CONTENT_PREFIX}_\#{x}")
end
EOC
end
def content_validate(tags) def content_validate(tags)
counter = {} counter = {}
@ -38,6 +42,7 @@ module RSS
end end
prefix_size = CONTENT_PREFIX.size + 1 prefix_size = CONTENT_PREFIX.size + 1
ContentModel::ELEMENTS.uniq!
ContentModel::ELEMENTS.each do |x| ContentModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], CONTENT_URI, "#{x}=") BaseListener.install_get_text_element(x[prefix_size..-1], CONTENT_URI, "#{x}=")
end end

View file

@ -111,44 +111,28 @@ EOC
end end
def def_to_euc_jp_from_shift_jis def def_to_euc_jp_from_shift_jis
begin require "nkf"
require "nkf"
rescue LoadError
raise UnknownConversionMethodError.new('EUC-JP', 'Shift_JIS')
end
def_convert do |value| def_convert do |value|
"NKF.nkf('-Se', #{value})" "NKF.nkf('-Se', #{value})"
end end
end end
def def_to_shift_jis_from_euc_jp def def_to_shift_jis_from_euc_jp
begin require "nkf"
require "nkf"
rescue LoadError
raise UnknownConversionMethodError.new('Shift_JIS', 'EUC-JP')
end
def_convert do |value| def_convert do |value|
"NKF.nkf('-Es', #{value})" "NKF.nkf('-Es', #{value})"
end end
end end
def def_to_euc_jp_from_iso_2022_jp def def_to_euc_jp_from_iso_2022_jp
begin require "nkf"
require "nkf"
rescue LoadError
raise UnknownConversionMethodError.new('EUC-JP', 'ISO-2022-JP')
end
def_convert do |value| def_convert do |value|
"NKF.nkf('-Je', #{value})" "NKF.nkf('-Je', #{value})"
end end
end end
def def_to_iso_2022_jp_from_euc_jp def def_to_iso_2022_jp_from_euc_jp
begin require "nkf"
require "nkf"
rescue LoadError
raise UnknownConversionMethodError.new('ISO-2022-JP', 'EUC-JP')
end
def_convert do |value| def_convert do |value|
"NKF.nkf('-Ej', #{value})" "NKF.nkf('-Ej', #{value})"
end end

View file

@ -13,14 +13,18 @@ module RSS
ELEMENTS = [] ELEMENTS = []
%w(title description creator subject publisher def self.included(mod)
contributor type format identifier source mod.module_eval(<<-EOC)
language relation coverage rights).each do |x| %w(title description creator subject publisher
install_text_element("#{DC_PREFIX}_#{x}") contributor type format identifier source
end language relation coverage rights).each do |x|
install_text_element("\#{DC_PREFIX}_\#{x}")
end
%w(date).each do |x| %w(date).each do |x|
install_date_element("#{DC_PREFIX}_#{x}", 'iso8601', x) install_date_element("\#{DC_PREFIX}_\#{x}", 'iso8601', x)
end
EOC
end end
def dc_validate(tags) def dc_validate(tags)
@ -47,6 +51,7 @@ module RSS
end end
prefix_size = DC_PREFIX.size + 1 prefix_size = DC_PREFIX.size + 1
DublincoreModel::ELEMENTS.uniq!
DublincoreModel::ELEMENTS.each do |x| DublincoreModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=") BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
end end

View file

@ -92,6 +92,8 @@ module RSS
include Utils include Utils
def install_have_child_element(name) def install_have_child_element(name)
add_need_initialize_variable(name)
attr_accessor name attr_accessor name
install_element(name) do |n, elem_name| install_element(name) do |n, elem_name|
<<-EOC <<-EOC
@ -106,8 +108,9 @@ EOC
alias_method(:install_have_attribute_element, :install_have_child_element) alias_method(:install_have_attribute_element, :install_have_child_element)
def install_have_children_element(name, postfix="s") def install_have_children_element(name, postfix="s")
def_children_accessor(name, postfix)
add_have_children_element(name) add_have_children_element(name)
def_children_accessor(name, postfix)
install_element(name, postfix) do |n, elem_name| install_element(name, postfix) do |n, elem_name|
<<-EOC <<-EOC
rv = '' rv = ''
@ -121,6 +124,8 @@ EOC
def install_text_element(name) def install_text_element(name)
self::ELEMENTS << name self::ELEMENTS << name
add_need_initialize_variable(name)
attr_writer name attr_writer name
convert_attr_reader name convert_attr_reader name
install_element(name) do |n, elem_name| install_element(name) do |n, elem_name|
@ -144,6 +149,7 @@ EOC
def install_date_element(name, type, disp_name=name) def install_date_element(name, type, disp_name=name)
self::ELEMENTS << name self::ELEMENTS << name
add_need_initialize_variable(name)
# accessor # accessor
convert_attr_reader name convert_attr_reader name
@ -323,6 +329,16 @@ EOC
@@have_children_elements << variable_name @@have_children_elements << variable_name
end 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 EOC
end end
@ -346,8 +362,9 @@ EOC
attr_accessor :do_validate attr_accessor :do_validate
def initialize(do_validate=true) def initialize(do_validate=true)
@converter = nil
@do_validate = do_validate @do_validate = do_validate
initialize_have_children_elements initialize_variables
end end
def tag_name def tag_name
@ -371,6 +388,13 @@ EOC
end end
private 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 def initialize_have_children_elements
self.class.have_children_elements.each do |variable_name| self.class.have_children_elements.each do |variable_name|
instance_eval("@#{variable_name} = []") instance_eval("@#{variable_name} = []")

View file

@ -13,13 +13,31 @@ module RSS
ELEMENTS = [] ELEMENTS = []
%w(updatePeriod updateFrequency).each do |x| def self.included(mod)
install_text_element("#{SY_PREFIX}_#{x}") mod.module_eval(<<-EOC)
end %w(updatePeriod updateFrequency).each do |x|
install_text_element("\#{SY_PREFIX}_\#{x}")
end
%w(updateBase).each do |x| %w(updateBase).each do |x|
install_date_element("#{SY_PREFIX}_#{x}", 'iso8601', x) install_date_element("\#{SY_PREFIX}_\#{x}", 'iso8601', x)
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
EOC
end
def sy_validate(tags) def sy_validate(tags)
counter = {} counter = {}
@ -35,21 +53,6 @@ module RSS
end end
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 private
SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly) SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
def validate_sy_updatePeriod(value) def validate_sy_updatePeriod(value)
@ -72,6 +75,7 @@ module RSS
end end
prefix_size = SY_PREFIX.size + 1 prefix_size = SY_PREFIX.size + 1
SyndicationModel::ELEMENTS.uniq!
SyndicationModel::ELEMENTS.each do |x| SyndicationModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=") BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=")
end end

View file

@ -1,7 +1,6 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit" require "test/unit"
require "rss/parser"
require "rss/1.0" require "rss/1.0"
require "rss/2.0" require "rss/2.0"
require "common" require "common"

View file

@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib" require "cgi-lib"
require "rexml/document" require "rexml/document"
require "rss/parser" require "rss/1.0"
require "rss/content" require "rss/content"
require "common" require "common"

View file

@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib" require "cgi-lib"
require "rexml/document" require "rexml/document"
require "rss/parser" require "rss/1.0"
require "rss/dublincore" require "rss/dublincore"
require "common" require "common"

View file

@ -1,7 +1,6 @@
# -*- tab-width: 2 -*- vim: ts=2 # -*- tab-width: 2 -*- vim: ts=2
require "test/unit" require "test/unit"
require "rss/parser"
require "rss/1.0" require "rss/1.0"
require "common" require "common"

View file

@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib" require "cgi-lib"
require "rexml/document" require "rexml/document"
require "rss/parser" require "rss/1.0"
require "rss/syndication" require "rss/syndication"
require "common" require "common"

View file

@ -4,7 +4,7 @@ require "test/unit"
require "cgi-lib" require "cgi-lib"
require "rexml/document" require "rexml/document"
require "rss/parser" require "rss/1.0"
require "rss/trackback" require "rss/trackback"
require "common" require "common"