* 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
Родитель 0b4597eccf
Коммит d5b6a7b169
25 изменённых файлов: 146 добавлений и 84 удалений

Просмотреть файл

@ -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>
* 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>
* 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
regular expression bug.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -13,35 +13,35 @@ module RSS
klass.__send__(:attr_accessor, element)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
def setup_#{element}(rss, current)
current.#{element} = #{element} if #{element}
if #{element} and current.respond_to?(:#{element}=)
current.#{element} = #{element}
end
end
EOC
end
end
end
class RSS10
class Channel
include DublinCoreModel
class ChannelBase
include DublinCoreModel
alias_method(:_dc_date, :dc_date)
alias_method(:_dc_date=, :dc_date=)
undef_method(: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=)
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
class TextinputBase; include DublinCoreModel; end
end
end

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -5,7 +5,7 @@ require "rss/maker"
module RSS
class TestMakerXMLStyleSheet < TestCase
def test_rss10
def test_xml_stylesheet
href = 'a.xsl'
type = 'text/xsl'
title = 'sample'
@ -47,6 +47,29 @@ module RSS
assert_equal(href, xss.href)
assert_equal(type, xss.type)
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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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