From bd4fd26fda94d3a0d75a130a025ea5b7b85a4f55 Mon Sep 17 00:00:00 2001 From: kou Date: Wed, 2 Feb 2005 13:00:31 +0000 Subject: [PATCH] * lib/rss/rss.rb (RSS::Element#convert): added. * lib/rss/rss.rb: convert -> need_convert. * lib/rss/1.0.rb: ditto. * lib/rss/0.9.rb: ditto. * lib/rss/2.0.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 +++++++++++ lib/rss/0.9.rb | 44 ++++++++++++++++++++-------------------- lib/rss/1.0.rb | 48 ++++++++++++++++++++++---------------------- lib/rss/2.0.rb | 10 ++++----- lib/rss/rss.rb | 30 +++++++++++++++++---------- lib/rss/trackback.rb | 8 ++++---- 6 files changed, 86 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55dd9ebd18..1ca807c8cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Wed Feb 2 21:56:01 2005 Kouhei Sutou + + * lib/rss/rss.rb (RSS::Element#convert): added. + + * lib/rss/rss.rb: convert -> need_convert. + + * lib/rss/1.0.rb: ditto. + + * lib/rss/0.9.rb: ditto. + + * lib/rss/2.0.rb: ditto. + Wed Feb 2 03:30:58 2005 Minero Aoki * ext/ripper/lib/ripper/tokenizer.rb -> lexer.rb. diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index 797a46ca3b..24560324ed 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -59,14 +59,14 @@ module RSS end end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent, ns_declarations) do |next_indent| [ channel_element(false, next_indent), other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -142,7 +142,7 @@ module RSS super() end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -165,7 +165,7 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -233,13 +233,13 @@ module RSS install_model(x, occurs) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ day_elements(false, next_indent) ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -278,13 +278,13 @@ module RSS install_model(x, occurs) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ hour_elements(false, next_indent) ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -331,7 +331,7 @@ module RSS install_model(x, "?") end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ url_element(false, next_indent), @@ -343,8 +343,8 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter - rv + rv = convert(rv) if need_convert + rv end private @@ -384,10 +384,10 @@ module RSS @protocol = protocol end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter - rv + rv = convert(rv) if need_convert + rv end private @@ -428,7 +428,7 @@ module RSS install_model(tag, occurs) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -440,8 +440,8 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter - rv + rv = convert(rv) if need_convert + rv end private @@ -533,9 +533,9 @@ module RSS @type = type end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -606,7 +606,7 @@ module RSS install_model(x, nil) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -616,8 +616,8 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter - rv + rv = convert(rv) if need_convert + rv end private diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb index 0e3e66ea95..86c19afc70 100644 --- a/lib/rss/1.0.rb +++ b/lib/rss/1.0.rb @@ -60,7 +60,7 @@ module RSS tag_name_with_prefix(PREFIX) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent, ns_declarations) do |next_indent| [ channel_element(false, next_indent), @@ -70,7 +70,7 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -118,11 +118,11 @@ module RSS @li = li end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) tag(indent) do |next_indent| [ - li_elements(convert, next_indent), - other_element(convert, next_indent), + li_elements(need_convert, next_indent), + other_element(need_convert, next_indent), ] end end @@ -177,9 +177,9 @@ module RSS tag_name_with_prefix(PREFIX) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -204,7 +204,7 @@ module RSS end - [ + [ ["about", URI, true] ].each do |name, uri, required| install_get_attribute(name, uri, required) @@ -234,7 +234,7 @@ module RSS @about = about end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -246,8 +246,8 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter - rv + rv = convert(rv) if need_convert + rv end private @@ -305,9 +305,9 @@ module RSS @resource = resource end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -342,9 +342,9 @@ module RSS @resource = resource end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -384,11 +384,11 @@ module RSS @Seq = seq end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ - Seq_element(convert, next_indent), - other_element(convert, next_indent), + Seq_element(need_convert, next_indent), + other_element(need_convert, next_indent), ] end end @@ -448,7 +448,7 @@ module RSS @about = about end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -457,7 +457,7 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -518,7 +518,7 @@ module RSS @about = about end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -527,7 +527,7 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -589,7 +589,7 @@ module RSS @about = about end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ title_element(false, next_indent), @@ -599,7 +599,7 @@ module RSS other_element(false, next_indent), ] end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb index 19cb487d79..6ed4fa02bf 100644 --- a/lib/rss/2.0.rb +++ b/lib/rss/2.0.rb @@ -30,11 +30,11 @@ module RSS install_model(x, occurs) end - def other_element(convert, indent) + def other_element(need_convert, indent) rv = <<-EOT -#{category_elements(convert, indent)} -#{generator_element(convert, indent)} -#{ttl_element(convert, indent)} +#{category_elements(need_convert, indent)} +#{generator_element(need_convert, indent)} +#{ttl_element(need_convert, indent)} EOT rv << super end @@ -86,7 +86,7 @@ EOT install_model(x, occurs) end - def other_element(convert, indent) + def other_element(need_convert, indent) rv = [ super, *%w(author comments pubDate guid).collect do |name| diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 216d514b8d..7ffb475007 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -164,7 +164,7 @@ module RSS install_element(name) do |n, elem_name| <<-EOC if @#{n} - "\#{@#{n}.to_s(convert, indent)}" + "\#{@#{n}.to_s(need_convert, indent)}" else '' end @@ -183,7 +183,7 @@ EOC <<-EOC rv = [] @#{n}.each do |x| - value = "\#{x.to_s(convert, indent)}" + value = "\#{x.to_s(need_convert, indent)}" rv << value if /\\A\\s*\\z/ !~ value end rv.join("\n") @@ -202,8 +202,8 @@ EOC if @#{n} rv = "\#{indent}<#{elem_name}>" value = html_escape(@#{n}) - if convert and @converter - rv << @converter.convert(value) + if need_convert + rv << convert(value) else rv << value end @@ -260,8 +260,8 @@ EOC if @#{n} rv = "\#{indent}<#{elem_name}>" value = html_escape(@#{n}.#{type}) - if convert and @converter - rv << @converter.convert(value) + if need_convert + rv << convert(value) else rv << value end @@ -279,7 +279,7 @@ EOC def install_element(name, postfix="") elem_name = name.sub('_', ':') module_eval(<<-EOC, *get_file_and_line_from_caller(2)) - def #{name}_element#{postfix}(convert=true, indent='') + def #{name}_element#{postfix}(need_convert=true, indent='') #{yield(name, elem_name)} end private :#{name}_element#{postfix} @@ -332,12 +332,12 @@ EOC def def_content_only_to_s module_eval(<<-EOC, *get_file_and_line_from_caller(2)) - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) if @content rv = tag(indent) do |next_indent| h(@content) end - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv else "" @@ -515,6 +515,14 @@ EOC child.converter = converter unless child.nil? end end + + def convert(value) + if @converter + @converter.convert(value) + else + value + end + end def validate validate_attribute @@ -692,12 +700,12 @@ EOC end end - def other_element(convert, indent='') + def other_element(need_convert, indent='') rv = [] private_methods.each do |meth| if /\A([^_]+)_[^_]+_elements?\z/ =~ meth and self.class::NSPOOL.has_key?($1) - res = __send__(meth, convert) + res = __send__(meth, need_convert) rv << "#{indent}#{res}" if /\A\s*\z/ !~ res end end diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb index 8bc1ee5ad5..439bdf3843 100644 --- a/lib/rss/trackback.rb +++ b/lib/rss/trackback.rb @@ -146,9 +146,9 @@ module RSS tag_name_with_prefix(TRACKBACK_PREFIX) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end @@ -194,9 +194,9 @@ module RSS tag_name_with_prefix(TRACKBACK_PREFIX) end - def to_s(convert=true, indent=calc_indent) + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) - rv = @converter.convert(rv) if convert and @converter + rv = convert(rv) if need_convert rv end