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

* test/rss/*.rb: removed tab width configuration headers.

* test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort.
* lib/rss/maker/*.rb: changed API to RSS version independence.
* lib/rss/maker/base.rb
  (RSS::Maker::XMLStyleSheets::XMLStyleSheet): checked required
  (pseudo) attributes.
* lib/rss/maker/base.rb (RSS::Maker::Items): sort -> do_sort.
* lib/rss/rss.rb (RSS::BaseModel.install_date_element): avoided warning.
* lib/rss/0.9.rb (RSS::Rss#textinput): added convenience method.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2004-11-03 06:43:18 +00:00
parent 0b4597eccf
commit d5b6a7b169
25 changed files with 146 additions and 84 deletions

View file

@ -1,3 +1,22 @@
Wed Nov 3 15:38:28 2004 Kouhei Sutou <kou@cozmixng.org>
* test/rss/*.rb: removed tab width configuration headers.
* test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort.
* lib/rss/maker/*.rb: changed API to RSS version independence.
* lib/rss/maker/base.rb
(RSS::Maker::XMLStyleSheets::XMLStyleSheet): checked required
(pseudo) attributes.
* lib/rss/maker/base.rb (RSS::Maker::Items): sort -> do_sort.
* lib/rss/rss.rb (RSS::BaseModel.install_date_element): avoided
warning.
* lib/rss/0.9.rb (RSS::Rss#textinput): added convenience method.
Tue Nov 2 16:35:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Nov 2 16:35:57 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/enumerator/enumerator.c (each_cons_i): pass copy of an * ext/enumerator/enumerator.c (each_cons_i): pass copy of an
@ -20,7 +39,7 @@ Tue Nov 2 01:20:09 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Mon Nov 1 22:25:56 2004 Kouhei Sutou <kou@cozmixng.org> Mon Nov 1 22:25:56 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb: changed xml-stylesheet's API of RSS Maker * lib/rss/maker/base.rb: changed xml-stylesheet's API of RSS Maker
like item's one. like to item's one.
* lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#guess_type): fixed * lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#guess_type): fixed
regular expression bug. regular expression bug.

View file

@ -51,6 +51,14 @@ module RSS
end end
end end
def textinput
if @channel
@channel.textInput
else
nil
end
end
def to_s(convert=true, indent=calc_indent) def to_s(convert=true, indent=calc_indent)
next_indent = indent + INDENT next_indent = indent + INDENT
rv = <<-EOR rv = <<-EOR

View file

@ -16,7 +16,7 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
klass.module_eval(<<-EOC) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(encoded).each do |x| %w(encoded).each do |x|
install_text_element("\#{CONTENT_PREFIX}_\#{x}") install_text_element("\#{CONTENT_PREFIX}_\#{x}")
end end

View file

@ -16,7 +16,7 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
klass.module_eval(<<-EOC) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(title description creator subject publisher %w(title description creator subject publisher
contributor type format identifier source contributor type format identifier source
language relation coverage rights).each do |x| language relation coverage rights).each do |x|

View file

@ -30,9 +30,6 @@ module RSS
class Channel < ChannelBase class Channel < ChannelBase
alias_method(:pubDate, :date)
alias_method(:pubDate=, :date=)
def to_rss(rss) def to_rss(rss)
channel = Rss::Channel.new channel = Rss::Channel.new
set = setup_values(channel) set = setup_values(channel)
@ -150,7 +147,7 @@ module RSS
setup_other_elements(rss) setup_other_elements(rss)
end end
end end
private private
def have_required_values? def have_required_values?
@title and @description and @name and @link @title and @description and @name and @link

View file

@ -48,8 +48,6 @@ module RSS
class Item < RSS09::Items::Item class Item < RSS09::Items::Item
alias_method(:pubDate, :date)
def have_required_values? def have_required_values?
@title or @description @title or @description
end end

View file

@ -16,26 +16,34 @@ module RSS
NEED_INITIALIZE_VARIABLES = [] NEED_INITIALIZE_VARIABLES = []
def self.inherited(subclass) def self.inherited(subclass)
subclass.const_set("OTHER_ELEMENTS", subclass.const_set("OTHER_ELEMENTS", [])
OTHER_ELEMENTS.dup) subclass.const_set("NEED_INITIALIZE_VARIABLES", [])
subclass.const_set("NEED_INITIALIZE_VARIABLES",
NEED_INITIALIZE_VARIABLES.dup) subclass.module_eval(<<-EOEOC, __FILE__, __LINE__)
def self.other_elements
const_get("OTHER_ELEMENTS") + super
end
def self.need_initialize_variables
const_get("NEED_INITIALIZE_VARIABLES") + super
end
EOEOC
end end
def self.add_other_element(variable_name) def self.add_other_element(variable_name)
const_get("OTHER_ELEMENTS") << variable_name const_get("OTHER_ELEMENTS") << variable_name
end end
def self.other_elements def self.other_elements
const_get("OTHER_ELEMENTS") OTHER_ELEMENTS
end end
def self.add_need_initialize_variable(variable_name) def self.add_need_initialize_variable(variable_name)
const_get("NEED_INITIALIZE_VARIABLES") << variable_name const_get("NEED_INITIALIZE_VARIABLES") << variable_name
end end
def self.need_initialize_variables def self.need_initialize_variables
const_get("NEED_INITIALIZE_VARIABLES") NEED_INITIALIZE_VARIABLES
end end
EOC EOC
end end
@ -84,10 +92,10 @@ module RSS
end end
end end
class RSSBase class RSSBase
include Base include Base
class << self class << self
def make(&block) def make(&block)
new.make(&block) new.make(&block)
@ -151,10 +159,12 @@ module RSS
class XMLStyleSheets class XMLStyleSheets
include Base include Base
include Enumerable
extend Forwardable extend Forwardable
def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last) def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last)
def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift) def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift)
def_delegators(:@xml_stylesheets, :each)
def initialize(maker) def initialize(maker)
super super
@ -183,11 +193,24 @@ module RSS
def to_rss(rss) def to_rss(rss)
xss = ::RSS::XMLStyleSheet.new xss = ::RSS::XMLStyleSheet.new
guess_type_if_need(xss)
set = setup_values(xss) set = setup_values(xss)
if set if set
rss.xml_stylesheets << xss rss.xml_stylesheets << xss
end end
end end
def have_required_values?
@href and @type
end
private
def guess_type_if_need(xss)
if @type.nil?
xss.href = @href
@type = xss.type
end
end
end end
end end
@ -204,6 +227,9 @@ module RSS
add_need_initialize_variable(element) add_need_initialize_variable(element)
end end
alias_method(:pubDate, :date)
alias_method(:pubDate=, :date=)
def initialize(maker) def initialize(maker)
super super
@cloud = make_cloud @cloud = make_cloud
@ -253,17 +279,19 @@ module RSS
class ItemsBase class ItemsBase
include Base include Base
include Enumerable
extend Forwardable extend Forwardable
def_delegators(:@items, :<<, :[], :[]=, :first, :last) def_delegators(:@items, :<<, :[], :[]=, :first, :last)
def_delegators(:@items, :push, :pop, :shift, :unshift) def_delegators(:@items, :push, :pop, :shift, :unshift)
def_delegators(:@items, :each)
attr_accessor :sort attr_accessor :do_sort
def initialize(maker) def initialize(maker)
super super
@items = [] @items = []
@sort = false @do_sort = false
end end
def normalize def normalize
@ -282,11 +310,11 @@ module RSS
private private
def sort_if_need def sort_if_need
if @sort.respond_to?(:call) if @do_sort.respond_to?(:call)
@items.sort do |x, y| @items.sort do |x, y|
@sort.call(x, y) @do_sort.call(x, y)
end end
elsif @sort elsif @do_sort
@items.sort do |x, y| @items.sort do |x, y|
y <=> x y <=> x
end end
@ -318,6 +346,9 @@ EOC
add_need_initialize_variable(element) add_need_initialize_variable(element)
end end
alias_method(:pubDate, :date)
alias_method(:pubDate=, :date=)
def initialize(maker) def initialize(maker)
super super
@guid = make_guid @guid = make_guid

View file

@ -13,17 +13,17 @@ module RSS
klass.__send__(:attr_accessor, element) klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current) def setup_#{element}(rss, current)
current.#{element} = @#{element} if @#{element} if #{element} and current.respond_to?(:#{element}=)
current.#{element} = @#{element} if @#{element}
end
end end
EOC EOC
end end
end end
end end
class RSS10 class ItemsBase
class Items class ItemBase; include ContentModel; end
class Item; include ContentModel; end
end
end end
end end
end end

View file

@ -13,35 +13,35 @@ module RSS
klass.__send__(:attr_accessor, element) klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current) def setup_#{element}(rss, current)
current.#{element} = #{element} if #{element} if #{element} and current.respond_to?(:#{element}=)
current.#{element} = #{element}
end
end end
EOC EOC
end end
end end
end end
class RSS10 class ChannelBase
class Channel include DublinCoreModel
include DublinCoreModel
alias_method(:_dc_date, :dc_date) undef_method(:dc_date)
alias_method(:_dc_date=, :dc_date=) undef_method(:dc_date=)
alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=)
end
class ImageBase; include DublinCoreModel; end
class ItemsBase
class ItemBase
include DublinCoreModel
undef_method(:dc_date)
undef_method(:dc_date=)
alias_method(:dc_date, :date) alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=) alias_method(:dc_date=, :date=)
end end
class Image; include DublinCoreModel; end
class Items
class Item
include DublinCoreModel
alias_method(:_dc_date, :dc_date)
alias_method(:_dc_date=, :dc_date=)
alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=)
end
end
class Textinput; include DublinCoreModel; end
end end
class TextinputBase; include DublinCoreModel; end
end end
end end

View file

@ -13,15 +13,15 @@ module RSS
klass.__send__(:attr_accessor, element) klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current) def setup_#{element}(rss, current)
current.#{element} = @#{element} if @#{element} if #{element} and current.respond_to?(:#{element}=)
current.#{element} = @#{element} if @#{element}
end
end end
EOC EOC
end end
end end
end end
class RSS10 class ChannelBase; include SyndicationModel; end
class Channel; include SyndicationModel; end
end
end end
end end

View file

@ -14,17 +14,17 @@ module RSS
klass.__send__(:attr_accessor, name) klass.__send__(:attr_accessor, name)
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{name}(rss, current) def setup_#{name}(rss, current)
current.#{name} = @#{name} if @#{name} if #{name} and current.respond_to?(:#{name}=)
current.#{name} = @#{name} if @#{name}
end
end end
EOC EOC
end end
end end
end end
class RSS10 class ItemsBase
class Items class ItemBase; include TrackBackModel; end
class Item; include TrackBackModel; end
end
end end
end end
end end

View file

@ -4,6 +4,7 @@
# Author:: Kouhei Sutou <kou@cozmixng.org> # Author:: Kouhei Sutou <kou@cozmixng.org>
# Tutorial:: http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en # Tutorial:: http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en
require "time" require "time"
class Time class Time
@ -234,7 +235,7 @@ EOC
# Is it need? # Is it need?
if @#{name} if @#{name}
class << @#{name} class << @#{name}
alias_method(:_to_s, :to_s) unless respond_to?(:_to_s) undef_method(:to_s)
alias_method(:to_s, :#{type}) alias_method(:to_s, :#{type})
end end
end end

View file

@ -16,7 +16,7 @@ module RSS
def self.append_features(klass) def self.append_features(klass)
super super
klass.module_eval(<<-EOC) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(updatePeriod updateFrequency).each do |x| %w(updatePeriod updateFrequency).each do |x|
install_text_element("\#{SY_PREFIX}_\#{x}") install_text_element("\#{SY_PREFIX}_\#{x}")
end end

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "rexml/document" require "rexml/document"
require "rss-testcase" require "rss-testcase"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "rss-testcase" require "rss-testcase"
require "rss/1.0" require "rss/1.0"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"

View file

@ -279,7 +279,7 @@ module RSS
item.link = "#{link}#{i}" item.link = "#{link}#{i}"
item.description = "#{description}#{i}" item.description = "#{description}#{i}"
end end
maker.items.sort maker.items.do_sort = true
end end
assert_equal(item_size, rss.items.size) assert_equal(item_size, rss.items.size)
rss.channel.items.each_with_index do |item, i| rss.channel.items.each_with_index do |item, i|
@ -298,7 +298,7 @@ module RSS
item.link = "#{link}#{i}" item.link = "#{link}#{i}"
item.description = "#{description}#{i}" item.description = "#{description}#{i}"
end end
maker.items.sort = Proc.new do |x, y| maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1] y.title[-1] <=> x.title[-1]
end end
end end

View file

@ -220,7 +220,7 @@ module RSS
item.link = "#{link}#{i}" item.link = "#{link}#{i}"
item.description = "#{description}#{i}" item.description = "#{description}#{i}"
end end
maker.items.sort = true maker.items.do_sort = true
end end
assert_equal(item_size, rss.items.size) assert_equal(item_size, rss.items.size)
rss.items.each_with_index do |item, i| rss.items.each_with_index do |item, i|
@ -239,7 +239,7 @@ module RSS
item.link = "#{link}#{i}" item.link = "#{link}#{i}"
item.description = "#{description}#{i}" item.description = "#{description}#{i}"
end end
maker.items.sort = Proc.new do |x, y| maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1] y.title[-1] <=> x.title[-1]
end end
end end

View file

@ -340,6 +340,7 @@ module RSS
item.comments = "#{comments}#{i}" item.comments = "#{comments}#{i}"
item.date = pubDate item.date = pubDate
end end
maker.items.do_sort = true
end end
assert_equal(item_size, rss.items.size) assert_equal(item_size, rss.items.size)
rss.channel.items.each_with_index do |item, i| rss.channel.items.each_with_index do |item, i|
@ -363,7 +364,7 @@ module RSS
item.comments = "#{comments}#{i}" item.comments = "#{comments}#{i}"
item.date = pubDate item.date = pubDate
end end
maker.items.sort = Proc.new do |x, y| maker.items.do_sort = Proc.new do |x, y|
y.title[-1] <=> x.title[-1] y.title[-1] <=> x.title[-1]
end end
end end

View file

@ -5,7 +5,7 @@ require "rss/maker"
module RSS module RSS
class TestMakerXMLStyleSheet < TestCase class TestMakerXMLStyleSheet < TestCase
def test_rss10 def test_xml_stylesheet
href = 'a.xsl' href = 'a.xsl'
type = 'text/xsl' type = 'text/xsl'
title = 'sample' title = 'sample'
@ -47,6 +47,29 @@ module RSS
assert_equal(href, xss.href) assert_equal(href, xss.href)
assert_equal(type, xss.type) assert_equal(type, xss.type)
end end
def test_not_valid_xml_stylesheet
href = 'xss.XXX'
type = "text/xsl"
rss = RSS::Maker.make("1.0") do |maker|
xss = maker.xml_stylesheets.new_xml_stylesheet
# xss.href = href
xss.type = type
setup_dummy_channel(maker)
end
assert(rss.xml_stylesheets.empty?)
rss = RSS::Maker.make("1.0") do |maker|
xss = maker.xml_stylesheets.new_xml_stylesheet
xss.href = href
# xss.type = type
setup_dummy_channel(maker)
end
assert(rss.xml_stylesheets.empty?)
end
end end
end end

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "rss-testcase" require "rss-testcase"
require "rss/1.0" require "rss/1.0"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "cgi" require "cgi"
require "rexml/document" require "rexml/document"

View file

@ -1,5 +1,3 @@
# -*- tab-width: 2 -*- vim: ts=2
require "rexml/document" require "rexml/document"
require "rss-testcase" require "rss-testcase"