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

* lib/rss/parser.rb, lib/rss/1.0.rb: accepted rdf:resource or

resource attribute in rdf:li.
* test/rss/test_parser.rb: added test for above change.
* lib/rss/dublincore.rb: reverted style.
* lib/rss/xmlparser.rb: normalized XMLParser class hierarchy.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2004-04-07 03:36:38 +00:00
parent 4ded52b623
commit 8dfa6fb0a8
9 changed files with 84 additions and 38 deletions

View file

@ -1,3 +1,13 @@
Wed Apr 7 12:32:02 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/parser.rb, lib/rss/1.0.rb: accepted rdf:resource or
resource attribute in rdf:li.
* test/rss/test_parser.rb: added test for above change.
* lib/rss/dublincore.rb: reverted style.
* lib/rss/xmlparser.rb: normalized XMLParser class hierarchy.
Wed Apr 7 10:43:17 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in, common.mk, */Makefile.sub (ext/extinit.o): OUTFLAG

View file

@ -150,7 +150,7 @@ EOT
end
[
["resource", nil, true]
["resource", [URI, nil], true]
].each do |name, uri, required|
install_get_attribute(name, uri, required)
end

View file

@ -46,11 +46,11 @@ module RSS
# For backward compatibility
DublincoreModel = DublinCoreModel
class RDF < Element
class Channel < Element; include DublinCoreModel; end
class Image < Element; include DublinCoreModel; end
class Item < Element; include DublinCoreModel; end
class Textinput < Element; include DublinCoreModel; end
class RDF
class Channel; include DublinCoreModel; end
class Image; include DublinCoreModel; end
class Item; include DublinCoreModel; end
class Textinput; include DublinCoreModel; end
end
prefix_size = DC_PREFIX.size + 1

View file

@ -260,19 +260,18 @@ module RSS
def start_else_element(local, prefix, attrs, ns)
class_name = local[0,1].upcase << local[1..-1]
current_class = @last_element.class
begin
# if current_class.const_defined?(class_name)
# begin
if current_class.constants.include?(class_name)
next_class = current_class.const_get(class_name)
start_have_something_element(local, prefix, attrs, ns, next_class)
rescue NameError
# else
# rescue NameError
else
if @ignore_unknown_element
@proc_stack.push(nil)
else
parent = "ROOT ELEMENT???"
begin
parent = current_class::TAG_NAME
rescue NameError
if current_class.const_defined?("TAG_NAME")
parent = current_class.const_get("TAG_NAME")
end
raise NotExceptedTagError.new(local, parent)
end
@ -317,14 +316,18 @@ module RSS
klass.get_attributes.each do |a_name, a_uri, required|
if a_uri
if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
a_uri = [a_uri]
end
unless a_uri == [nil]
for prefix, uri in ns
if uri == a_uri
if a_uri.include?(uri)
val = attrs["#{prefix}:#{a_name}"]
break if val
end
end
else
end
if val.nil? and a_uri.include?(nil)
val = attrs[a_name]
end

View file

@ -1,7 +1,7 @@
require "time"
class Time
class << Time
class << self
unless respond_to?(:w3cdtf)
def w3cdtf(date)
if /\A\s*
@ -510,11 +510,8 @@ EOC
if not_shift
not_shift = false
else
begin
tag = tags.shift
rescue NameError
end
elsif tags
tag = tags.shift
end
if DEBUG
@ -551,11 +548,9 @@ EOC
end
else
if elem[0] == tag
begin
if model[i+1][0] != elem[0] and tags.first == elem[0]
raise TooMuchTagError.new(elem[0], tag_name)
end
rescue NameError # for model[i+1][0] and tags.first
if model[i+1] and model[i+1][0] != elem[0] and
tags and tags.first == elem[0]
raise TooMuchTagError.new(elem[0], tag_name)
end
else
raise MissingTagError.new(elem[0], tag_name)

View file

@ -17,6 +17,14 @@ rescue LoadError
end
end
module XML
class Parser
unless defined?(Error)
Error = ::XMLParserError
end
end
end
module RSS
class REXMLLikeXMLParser < ::XML::Parser

View file

@ -10,7 +10,6 @@ class String
end
end
require "rss/parser"
require "rss/1.0"
require "rss/2.0"
require "rss/dublincore"
@ -72,13 +71,14 @@ processing_time = Time.now - before_time
channels.sort do |x, y|
x[0] <=> y[0]
end[0..20].each do |title, items|
puts "Channel : #{title}" unless items.empty?
puts "Channel: #{title}" unless items.empty?
items.sort do |x, y|
x.title <=> y.title
end[0..10].each do |item|
puts " Item : #{item.title.shorten(50)}"
puts " Description : #{item.description.shorten(50)}"
puts " Item: #{item.title.shorten(50)}"
puts " Description: #{item.description.shorten(50)}"
end
end
puts "Processing Time : #{processing_time}s"
puts "Used XML parser: #{RSS::Parser.default_parser}"
puts "Processing time: #{processing_time}s"

View file

@ -10,10 +10,8 @@ class String
end
end
require "rss/parser"
require "rss/1.0"
require "rss/2.0"
require "rss/syndication"
require "rss/dublincore"
items = []
@ -76,9 +74,10 @@ processing_time = Time.now - before_time
items.sort do |x, y|
y[1].dc_date <=> x[1].dc_date
end[0..20].each do |channel, item|
puts "#{item.dc_date.localtime.iso8601} : " <<
"#{channel.title} : #{item.title}"
puts " description : #{item.description.shorten(50)}" if item.description
puts "#{item.dc_date.localtime.iso8601}: " <<
"#{channel.title}: #{item.title}"
puts " Description: #{item.description.shorten(50)}" if item.description
end
puts "Processing Time : #{processing_time}s"
puts "Used XML parser: #{RSS::Parser.default_parser}"
puts "Processing time: #{processing_time}s"

View file

@ -219,6 +219,37 @@ EOR
end
def test_rdf_li
rss = make_RDF(<<-EOR)
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
<description>hogehoge</description>
<image rdf:resource="http://example.com/hoge.png" />
<items>
<rdf:Seq>
<rdf:li \#{rdf_li_attr}/>
</rdf:Seq>
</items>
<textinput rdf:resource="http://example.com/search" />
</channel>
#{make_item}
EOR
source = Proc.new do |rdf_li_attr|
eval(%Q[%Q[#{rss}]], binding)
end
attr = %q[resource="http://example.com/hoge"]
assert_parse(source.call(attr), :nothing_raised)
attr = %q[rdf:resource="http://example.com/hoge"]
assert_parse(source.call(attr), :nothing_raised)
assert_parse(source.call(""), :missing_attribute, "li", "resource")
end
def test_image
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")