summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-23 09:24:17 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-23 09:24:17 +0000
commit4ef7ec62cab725ad1dea2be9a26ca0f9fd195729 (patch)
tree2433c8b783f7af942de18409be11a6fded9852c9 /lib
parentf988ceb53b731f7465f8ace09c76cd69e9abef22 (diff)
* lib/rss/maker/taxonomy.rb: implemented taxonomy module for RSS
Maker. * lib/rss/taxonomy.rb: supported RSS Maker. * lib/rss/maker.rb: added taxonomy module support. * lib/rss/rss.rb: adjusted to other element API. * lib/rss/1.0.rb: adjusted to other element API but backward compatibility is reserved. * lib/rss/0.9.rb: ditto. * test/rss/test_maker_taxo.rb: added test case for taxonomy module for RSS Maker. * test/rss/test_setup_maker_1.0.rb: added tests for taxo:topic. * test/rss/test_setup_maker_1.0.rb: added backward compatibility test. * test/rss/test_setup_maker_0.9.rb: ditto. * test/rss/test_setup_maker_2.0.rb: ditto. * test/rss/rss-testcase.rb: added convenience method for setting up taxo:topic. * test/rss/rss-assertions.rb: added assertion for taxo:topic. * sample/rss/blend.rb: followed new API. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rss/0.9.rb8
-rw-r--r--lib/rss/1.0.rb20
-rw-r--r--lib/rss/maker.rb1
-rw-r--r--lib/rss/maker/taxonomy.rb178
-rw-r--r--lib/rss/rss.rb5
-rw-r--r--lib/rss/taxonomy.rb10
6 files changed, 213 insertions, 9 deletions
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index 3bbf67be05..41b8fced73 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -472,8 +472,12 @@ module RSS
rv
end
- def maker_target(maker)
- maker.items.new_item
+ def maker_target(items)
+ if items.respond_to?("items")
+ # For backward compatibility
+ items = items.items
+ end
+ items.new_item
end
def setup_maker_element(item)
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
index 5c7e3f5e62..00d8c3abdb 100644
--- a/lib/rss/1.0.rb
+++ b/lib/rss/1.0.rb
@@ -170,6 +170,12 @@ module RSS
tag_name_with_prefix(PREFIX)
end
+ def setup_maker(target)
+ lis.each do |li|
+ target << li.resource
+ end
+ end
+
private
def children
@li
@@ -224,6 +230,12 @@ module RSS
tag_name_with_prefix(PREFIX)
end
+ def setup_maker(target)
+ lis.each do |li|
+ target << li.resource
+ end
+ end
+
private
def children
@li
@@ -600,8 +612,12 @@ module RSS
]
end
- def maker_target(maker)
- maker.items.new_item
+ def maker_target(items)
+ if items.respond_to?("items")
+ # For backward compatibility
+ items = items.items
+ end
+ items.new_item
end
end
diff --git a/lib/rss/maker.rb b/lib/rss/maker.rb
index d248711aa2..9ed799ac7f 100644
--- a/lib/rss/maker.rb
+++ b/lib/rss/maker.rb
@@ -32,5 +32,6 @@ require "rss/maker/2.0"
require "rss/maker/content"
require "rss/maker/dublincore"
require "rss/maker/syndication"
+require "rss/maker/taxonomy"
require "rss/maker/trackback"
require "rss/maker/image"
diff --git a/lib/rss/maker/taxonomy.rb b/lib/rss/maker/taxonomy.rb
new file mode 100644
index 0000000000..0249afc2f2
--- /dev/null
+++ b/lib/rss/maker/taxonomy.rb
@@ -0,0 +1,178 @@
+require 'rss/taxonomy'
+require 'rss/maker/1.0'
+require 'rss/maker/dublincore'
+
+module RSS
+ module Maker
+ module TaxoTopicsModel
+ def self.append_features(klass)
+ super
+
+ klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
+ klass.add_other_element("taxo_topics")
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ attr_reader :taxo_topics
+ def make_taxo_topics
+ self.class::TaxoTopics.new(@maker)
+ end
+
+ def setup_taxo_topics(rss, current)
+ @taxo_topics.to_rss(rss, current)
+ end
+EOC
+ end
+
+ def self.install_taxo_topics(klass)
+ klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
+ class TaxoTopics < TaxoTopicsBase
+ def to_rss(rss, current)
+ if current.respond_to?(:taxo_topics)
+ topics = current.class::TaxoTopics.new
+ bag = topics.Bag
+ @resources.each do |resource|
+ bag.lis << RDF::Bag::Li.new(resource)
+ end
+ current.taxo_topics = topics
+ end
+ end
+ end
+EOC
+ end
+
+ class TaxoTopicsBase
+ include Base
+
+ attr_reader :resources
+ def_array_element("resources")
+ end
+ end
+
+ module TaxoTopicModel
+ def self.append_features(klass)
+ super
+
+ klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
+ klass.add_other_element("taxo_topics")
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
+ attr_reader :taxo_topics
+ def make_taxo_topics
+ self.class::TaxoTopics.new(@maker)
+ end
+
+ def setup_taxo_topics(rss, current)
+ @taxo_topics.to_rss(rss, current)
+ end
+
+ def taxo_topic
+ @taxo_topics[0] and @taxo_topics[0].value
+ end
+
+ def taxo_topic=(new_value)
+ @taxo_topic[0] = self.class::TaxoTopic.new(self)
+ @taxo_topic[0].value = new_value
+ end
+EOC
+ end
+
+ def self.install_taxo_topic(klass)
+ klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
+ class TaxoTopics < TaxoTopicsBase
+ class TaxoTopic < TaxoTopicBase
+ DublinCoreModel.install_dublin_core(self)
+ TaxoTopicsModel.install_taxo_topics(self)
+
+ def to_rss(rss, current)
+ if current.respond_to?(:taxo_topics)
+ topic = current.class::TaxoTopic.new(value)
+ topic.taxo_link = value
+ taxo_topics.to_rss(rss, topic) if taxo_topics
+ current.taxo_topics << topic
+ setup_other_elements(rss)
+ end
+ end
+
+ def current_element(rss)
+ super.taxo_topics.last
+ end
+ end
+ end
+EOC
+ end
+
+ class TaxoTopicsBase
+ include Base
+
+ def_array_element("taxo_topics")
+
+ def new_taxo_topic
+ taxo_topic = self.class::TaxoTopic.new(self)
+ @taxo_topics << taxo_topic
+ taxo_topic
+ end
+
+ def to_rss(rss, current)
+ @taxo_topics.each do |taxo_topic|
+ taxo_topic.to_rss(rss, current)
+ end
+ end
+
+ class TaxoTopicBase
+ include Base
+ include DublinCoreModel
+ include TaxoTopicsModel
+
+ attr_accessor :value
+ add_need_initialize_variable("value")
+ alias_method(:taxo_link, :value)
+ alias_method(:taxo_link=, :value=)
+
+ def have_required_values?
+ @value
+ end
+ end
+ end
+ end
+
+ class RSSBase
+ include TaxoTopicModel
+ end
+
+ class ChannelBase
+ include TaxoTopicsModel
+ end
+
+ class ItemsBase
+ class ItemBase
+ include TaxoTopicsModel
+ end
+ end
+
+ class RSS10
+ TaxoTopicModel.install_taxo_topic(self)
+
+ class Channel
+ TaxoTopicsModel.install_taxo_topics(self)
+ end
+
+ class Items
+ class Item
+ TaxoTopicsModel.install_taxo_topics(self)
+ end
+ end
+ end
+
+ class RSS09
+ TaxoTopicModel.install_taxo_topic(self)
+
+ class Channel
+ TaxoTopicsModel.install_taxo_topics(self)
+ end
+
+ class Items
+ class Item
+ TaxoTopicsModel.install_taxo_topics(self)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 7ccf1aefa1..7acbef275d 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -655,7 +655,6 @@ EOC
def setup_maker_elements(parent)
self.class.have_children_elements.each do |name, plural_name|
- real_name = name.sub(/^[^_]+_/, '')
if parent.respond_to?(plural_name)
target = parent.__send__(plural_name)
__send__(plural_name).each do |elem|
@@ -894,9 +893,7 @@ EOC
channel.setup_maker(maker) if channel
image.setup_maker(maker) if image
textinput.setup_maker(maker) if textinput
- items.each do |item|
- item.setup_maker(maker)
- end
+ super(maker)
end
end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
index 3eb5b893aa..d2ab7df854 100644
--- a/lib/rss/taxonomy.rb
+++ b/lib/rss/taxonomy.rb
@@ -76,6 +76,10 @@ module RSS
def full_name
tag_name_with_prefix(TAXO_PREFIX)
end
+
+ def maker_target(target)
+ target.taxo_topics
+ end
def to_s(need_convert=true, indent=calc_indent)
rv = tag(indent) do |next_indent|
@@ -95,7 +99,7 @@ module RSS
[]
end
end
-
+
private
def children
[@Bag]
@@ -183,6 +187,10 @@ module RSS
end
end
+ def maker_target(target)
+ target.new_taxo_topic
+ end
+
private
def children
[@taxo_link, @taxo_topics]