summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-03 06:43:18 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-03 06:43:18 +0000
commitd5b6a7b16947aaf4821d6b76c7de153866fb30c0 (patch)
tree450b783d2d0ee2af19ba3efb8324e73a5e0fc1d5 /lib
parent0b4597eccfb5ee078e546c910f2f3cee31d3274b (diff)
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/rss/0.9.rb8
-rw-r--r--lib/rss/content.rb2
-rw-r--r--lib/rss/dublincore.rb2
-rw-r--r--lib/rss/maker/0.9.rb5
-rw-r--r--lib/rss/maker/2.0.rb2
-rw-r--r--lib/rss/maker/base.rb61
-rw-r--r--lib/rss/maker/content.rb12
-rw-r--r--lib/rss/maker/dublincore.rb38
-rw-r--r--lib/rss/maker/syndication.rb10
-rw-r--r--lib/rss/maker/trackback.rb12
-rw-r--r--lib/rss/rss.rb3
-rw-r--r--lib/rss/syndication.rb2
12 files changed, 96 insertions, 61 deletions
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index d5c6b3a89d..c772e80870 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -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
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index 4367d16d92..280bbb8d6b 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -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
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index 417ab5b179..7ea9cf31dd 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -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|
diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb
index 7223246647..05578082b0 100644
--- a/lib/rss/maker/0.9.rb
+++ b/lib/rss/maker/0.9.rb
@@ -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
diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb
index 2fa61e80e6..05fc46480a 100644
--- a/lib/rss/maker/2.0.rb
+++ b/lib/rss/maker/2.0.rb
@@ -48,8 +48,6 @@ module RSS
class Item < RSS09::Items::Item
- alias_method(:pubDate, :date)
-
def have_required_values?
@title or @description
end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index eb61f37ee2..21222351f2 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -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
diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb
index 67b237f4ef..96f3ccb6d9 100644
--- a/lib/rss/maker/content.rb
+++ b/lib/rss/maker/content.rb
@@ -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
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
index 6a4c64a464..a9b8d58715 100644
--- a/lib/rss/maker/dublincore.rb
+++ b/lib/rss/maker/dublincore.rb
@@ -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
diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb
index ad846413ae..72d00c63ea 100644
--- a/lib/rss/maker/syndication.rb
+++ b/lib/rss/maker/syndication.rb
@@ -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
diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb
index ff0e1abe44..1ec59ab0b0 100644
--- a/lib/rss/maker/trackback.rb
+++ b/lib/rss/maker/trackback.rb
@@ -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
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 231fb1fb62..b6afa24b93 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -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
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index b8200ad70d..c274ff8c82 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -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