summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-21 09:20:47 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-03-21 09:20:47 +0000
commit7ead69e5b3a2b09878037f11a7dda59ae402ccbf ()
treef7a422e5983f2c475c831e5d70987437eb77fa69
parent2639d6dc809a3f78c96543c839d72d05e6e90ca7 (diff)
* test/rss/test_xml-stylesheet.rb: added tests for xml-stylesheet.
* lib/rss/xml-stylesheet.rb: added xml-stylesheet parsing function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/rss/0.9.rb35
-rw-r--r--lib/rss/1.0.rb50
-rw-r--r--lib/rss/2.0.rb1
-rw-r--r--lib/rss/converter.rb12
-rw-r--r--lib/rss/parser.rb28
-rw-r--r--lib/rss/rss.rb43
-rw-r--r--lib/rss/utils.rb6
-rw-r--r--lib/rss/xml-stylesheet.rb94
-rw-r--r--lib/rss/xmlparser.rb14
-rw-r--r--lib/rss/xmlscanner.rb1
-rw-r--r--test/rss/common.rb9
-rw-r--r--test/rss/my-assertions.rb39
-rw-r--r--test/rss/test_1.0.rb22
-rw-r--r--test/rss/test_xml-stylesheet.rb109
15 files changed, 385 insertions, 85 deletions
@@ -1,3 +1,10 @@
Sat Mar 20 23:51:03 2004 WATANABE Hirofumi <[email protected]>
* eval.c (rb_require_safe): preserve old ruby_errinfo.
@@ -10,6 +10,8 @@ module RSS
class Rss < Element
include RSS09
[
["channel", nil],
@@ -24,18 +26,9 @@ module RSS
attr_accessor :rss_version, :version, :encoding, :standalone
def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
- super()
- @rss_version = rss_version
- @version = version || '1.0'
- @encoding = encoding
- @standalone = standalone
end
- def output_encoding=(enc)
- @output_encoding = enc
- self.converter = Converter.new(@output_encoding, @encoding)
- end
-
def items
if @channel
@channel.items
@@ -55,7 +48,7 @@ module RSS
def to_s(convert=true)
rv = <<-EOR
#{xmldecl}
-<rss version="#{@rss_version}"#{ns_declaration}>
#{channel_element(false)}
#{other_element(false, "\t")}
</rss>
@@ -65,25 +58,6 @@ EOR
end
private
- def xmldecl
- rv = "<?xml version='#{@version}'"
- if @output_encoding or @encoding
- rv << " encoding='#{@output_encoding or @encoding}'"
- end
- rv << " standalone='#{@standalone}'" if @standalone
- rv << '?>'
- rv
- end
-
- def ns_declaration
- rv = ''
- NSPOOL.each do |prefix, uri|
- prefix = ":#{prefix}" unless prefix.empty?
- rv << %Q|\n\txmlns#{prefix}="#{uri}"|
- end
- rv
- end
-
def children
[@channel]
end
@@ -423,6 +397,7 @@ EOT
check_ns(tag_name, prefix, ns, nil)
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
@last_element = @rss
@proc_stack.push Proc.new { |text, tags|
@rss.validate_for_stream(tags) if @do_validate
@@ -10,6 +10,8 @@ module RSS
class RDF < Element
include RSS10
class << self
@@ -45,23 +47,13 @@ module RSS
attr_accessor :rss_version, :version, :encoding, :standalone
def initialize(version=nil, encoding=nil, standalone=nil)
- super()
- @rss_version = '1.0'
- @version = version || '1.0'
- @encoding = encoding
- @standalone = standalone
- @output_encoding = nil
- end
-
- def output_encoding=(enc)
- @output_encoding = enc
- self.converter = Converter.new(@output_encoding, @encoding)
end
def to_s(convert=true)
rv = <<-EORDF
#{xmldecl}
-<#{PREFIX}:RDF#{ns_declaration}>
#{channel_element(false)}
#{image_element(false)}
#{item_elements(false)}
@@ -74,25 +66,6 @@ EORDF
end
private
- def xmldecl
- rv = %Q[<?xml version="#{@version}"]
- if @output_encoding or @encoding
- rv << %Q[ encoding="#{@output_encoding or @encoding}"]
- end
- rv << %Q[ standalone="#{@standalone}"] if @standalone
- rv << '?>'
- rv
- end
-
- def ns_declaration
- rv = ''
- self.class::NSPOOL.each do |prefix, uri|
- prefix = ":#{prefix}" unless prefix.empty?
- rv << %Q|\n\txmlns#{prefix}="#{html_escape(uri)}"|
- end
- rv
- end
-
def rdf_validate(tags)
_validate(tags, [])
end
@@ -647,4 +620,19 @@ EOT
BaseListener.install_get_text_element(x, URI, "#{x}=")
end
end
@@ -135,6 +135,7 @@ EOT
# check_ns(tag_name, prefix, ns, Rss::URI)
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
@last_element = @rss
@proc_stack.push Proc.new { |text, tags|
@rss.validate_for_stream(tags) if @do_validate
@@ -25,8 +25,8 @@ module RSS
value
end
- def def_convert()
- instance_eval(<<-EOC, *get_file_and_line_from_caller(0))
def convert(value)
if value.kind_of?(String)
#{yield('value')}
@@ -37,10 +37,10 @@ module RSS
EOC
end
- def def_iconv_convert(to_enc, from_enc)
begin
require "iconv"
- def_convert do |value|
<<-EOC
@iconv ||= Iconv.new("#{to_enc}", "#{from_enc}")
begin
@@ -68,7 +68,7 @@ module RSS
def def_uconv_convert_if_can(meth, to_enc, from_enc)
begin
require "uconv"
- def_convert do |value|
<<-EOC
begin
Uconv.#{meth}(#{value})
@@ -78,7 +78,7 @@ module RSS
EOC
end
rescue LoadError
- def_iconv_convert(to_enc, from_enc)
end
end
@@ -191,12 +191,22 @@ module RSS
@proc_stack = []
@last_element = nil
@version = @encoding = @standalone = nil
end
def xmldecl(version, encoding, standalone)
@version, @encoding, @standalone = version, encoding, standalone
end
def tag_start(name, attributes)
@text_stack.push('')
@@ -204,7 +214,7 @@ module RSS
attrs = {}
attributes.each do |n, v|
if n =~ /\Axmlns:?/
- ns[$'] = v # $' is post match
else
attrs[n] = v
end
@@ -238,15 +248,13 @@ module RSS
private
- def start_RDF(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, RDF::URI)
-
- @rss = RDF.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @last_element = @rss
- @proc_stack.push Proc.new { |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- }
end
def start_else_element(local, prefix, attrs, ns)
@@ -1,7 +1,9 @@
require "time"
require "rss/utils"
require "rss/converter"
module RSS
@@ -365,7 +367,6 @@ EOC
def initialize(do_validate=true)
@converter = nil
- @output_encoding = nil
@do_validate = do_validate
initialize_variables
end
@@ -561,4 +562,44 @@ EOC
end
end
@@ -3,10 +3,8 @@ module RSS
module Utils
def get_file_and_line_from_caller(i=0)
- tmp = caller[i].split(':')
- line = tmp.pop.to_i
- file = tmp.join(':')
- [file, line]
end
def html_escape(s)
@@ -0,0 +1,94 @@
@@ -1,4 +1,10 @@
begin
require "xml/encoding-ja"
rescue LoadError
require "xmlencoding-ja"
@@ -15,7 +21,7 @@ module RSS
class REXMLLikeXMLParser < ::XML::Parser
- include XML::Encoding_ja
def listener=(listener)
@listener = listener
@@ -37,6 +43,10 @@ module RSS
@listener.xmldecl(version, encoding, standalone == 1)
end
end
class XMLParserParser < BaseParser
@@ -51,7 +61,7 @@ module RSS
parser = REXMLLikeXMLParser.new
parser.listener = @listener
parser.parse(@rss)
- rescue XMLParserError => e
raise NotWellFormedError.new(parser.line){e.message}
end
end
@@ -48,6 +48,7 @@ module RSS
xmldecl(@version, @encoding, @standalone)
end
alias_method(:on_chardata, :text)
alias_method(:on_cdata, :text)
@@ -100,6 +100,15 @@ EOI
EOT
end
def make_Rss2(content=nil, xmlns=[])
<<-EORSS
#{make_xmldecl}
@@ -84,7 +84,46 @@ module Test
end
end
end
end
end
end
@@ -38,8 +38,28 @@ class TestCore < Test::Unit::TestCase
end
- def test_channel
about = "http://hoge.com"
title = "fugafuga"
link = "http://hoge.com"
@@ -0,0 +1,109 @@