diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 17:43:05 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 17:43:05 +0000 |
commit | e289fcf81a22f1dc6ebcb87861877b463af04b7c (patch) | |
tree | ef88a6dfdfc68d57025eb98ab6fe8d237c3adccd /lib/rss/0.9.rb | |
parent | 9800838ff02369fa9e393b70f40b6083af0ce595 (diff) | |
download | ruby-e289fcf81a22f1dc6ebcb87861877b463af04b7c.tar.gz |
* lib/rss/{rss,parser,0.9,1.0,2.0}.rb: supported RSS 0.9x/2.0
validation and validation which disregard order of elements.
* test/rss/test_parser.rb: added tests for RSS 0.9x/2.0
validation.
* test/rss/{test_trackback,rss-testcase}.rb: fixed no good method
name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss/0.9.rb')
-rw-r--r-- | lib/rss/0.9.rb | 166 |
1 files changed, 136 insertions, 30 deletions
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index bb3cc23beb..c95c47e974 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -5,6 +5,12 @@ module RSS module RSS09 NSPOOL = {} ELEMENTS = [] + + def self.append_features(klass) + super + + klass.install_must_call_validator('', nil) + end end class Rss < Element @@ -62,22 +68,34 @@ EOR [@channel] end + def _tags + [ + [nil, 'channel'], + ].delete_if {|x| send(x[1]).nil?} + end + + def _attrs + [ + ["version", true], + ] + end + class Channel < Element include RSS09 [ ["title", nil], - ["link", nil], - ["description", nil], - ["language", nil], - ["copyright", "?"], - ["managingEditor", "?"], - ["webMaster", "?"], - ["rating", "?"], - ["docs", "?"], - ["skipDays", "?"], - ["skipHours", "?"], + ["link", nil], + ["description", nil], + ["language", nil], + ["copyright", "?"], + ["managingEditor", "?"], + ["webMaster", "?"], + ["rating", "?"], + ["docs", "?"], + ["skipDays", "?"], + ["skipHours", "?"], ].each do |x, occurs| install_text_element(x) install_model(x, occurs) @@ -85,7 +103,7 @@ EOR [ ["pubDate", "?"], - ["lastBuildDate", "?"], + ["lastBuildDate", "?"], ].each do |x, occurs| install_date_element(x, 'rfc822') install_model(x, occurs) @@ -93,14 +111,20 @@ EOR [ ["image", nil], - ["textInput", "?"], - ["cloud", "?"] + ["textInput", "?"], ].each do |x, occurs| install_have_child_element(x) install_model(x, occurs) end [ + ["cloud", "?"] + ].each do |x, occurs| + install_have_attribute_element(x) + install_model(x, occurs) + end + + [ ["item", "*"] ].each do |x, occurs| install_have_children_element(x) @@ -142,12 +166,46 @@ EOT [@image, @textInput, @cloud, *@item] end + def _tags + rv = [ + "title", + "link", + "description", + "language", + "copyright", + "managingEditor", + "webMaster", + "rating", + "docs", + "skipDays", + "skipHours", + "image", + "textInput", + "cloud", + ].delete_if do |x| + send(x).nil? + end.collect do |elem| + [nil, elem] + end + + @item.each do + rv << [nil, "item"] + end + + rv + end + class Image < Element include RSS09 - %w(url title link width height description).each do |x| + %w(url title link).each do |x| install_text_element(x) + install_model(x, nil) + end + %w(width height description).each do |x| + install_text_element(x) + install_model(x, "?") end def to_s(convert=true) @@ -166,6 +224,14 @@ EOT rv end + private + def _tags + %w(url title link width height description).delete_if do |x| + send(x).nil? + end.collect do |elem| + [nil, elem] + end + end end class Cloud < Element @@ -173,15 +239,24 @@ EOT include RSS09 [ - ["domain", nil, false], - ["port", nil, false], - ["path", nil, false], - ["registerProcedure", nil, false], - ["protocol", nil ,false], + ["domain", nil, true], + ["port", nil, true], + ["path", nil, true], + ["registerProcedure", nil, true], + ["protocol", nil ,true], ].each do |name, uri, required| install_get_attribute(name, uri, required) end + def initialize(domain, port, path, rp, protocol) + super() + @domain = domain + @port = port + @path = path + @registerProcedure = rp + @protocol = protocol + end + def to_s(convert=true) rv = <<-EOT <cloud @@ -195,13 +270,20 @@ EOT rv end + private + def _attrs + %w(domain port path registerProcedure protocol).collect do |attr| + [attr, true] + end + end + end class Item < Element include RSS09 - %w(title link description author comments).each do |x| + %w(title link description).each do |x| install_text_element(x) end @@ -213,8 +295,6 @@ EOT ["title", '?'], ["link", '?'], ["description", '?'], - ["author", '?'], - ["comments", '?'], ["category", '?'], ["source", '?'], ["enclosure", '?'], @@ -228,11 +308,9 @@ EOT #{title_element(false)} #{link_element(false)} #{description_element(false)} - #{author_element(false)} #{category_element(false)} - #{comments_element(false)} - #{enclosure_element(false)} #{source_element(false)} + #{enclosure_element(false)} #{other_element(false, "\t\t\t\t")} </item> EOT @@ -240,6 +318,20 @@ EOT rv end + private + def children + [@category, @source, @enclosure,].compact + end + + def _tags + %w(title link description author comments category + source enclosure).delete_if do |x| + send(x).nil? + end.collect do |x| + [nil, x] + end + end + class Source < Element include RSS09 @@ -249,7 +341,7 @@ EOT ].each do |name, uri, required| install_get_attribute(name, uri, required) end - + content_setup def initialize(url=nil, content=nil) @@ -270,6 +362,10 @@ EOT end private + def _tags + [] + end + def _attrs [ ["url", true] @@ -284,8 +380,8 @@ EOT [ ["url", nil, true], - ["length", nil, true], - ["type", nil, true], + ["length", nil, true], + ["type", nil, true], ].each do |name, uri, required| install_get_attribute(name, uri, required) end @@ -312,8 +408,8 @@ EOT def _attrs [ ["url", true], - ["length", true], - ["type", true], + ["length", true], + ["type", true], ] end @@ -365,6 +461,7 @@ EOT %w(title description name link).each do |x| install_text_element(x) + install_model(x, nil) end def to_s(convert=true) @@ -381,6 +478,14 @@ EOT rv end + private + def _tags + %w(title description name link).each do |x| + send(x).nil? + end.collect do |elem| + [nil, elem] + end + end end end @@ -397,6 +502,7 @@ EOT check_ns(tag_name, prefix, ns, nil) @rss = Rss.new(attrs['version'], @version, @encoding, @standalone) + @rss.do_validate = @do_validate @rss.xml_stylesheets = @xml_stylesheets @last_element = @rss @proc_stack.push Proc.new { |text, tags| |