2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2005-11-23 12:24:17 +03:00
|
|
|
require 'rss/taxonomy'
|
|
|
|
require 'rss/maker/1.0'
|
|
|
|
require 'rss/maker/dublincore'
|
|
|
|
|
|
|
|
module RSS
|
|
|
|
module Maker
|
2005-11-23 12:32:22 +03:00
|
|
|
module TaxonomyTopicsModel
|
2005-11-23 12:24:17 +03:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
klass.def_classed_element("#{RSS::TAXO_PREFIX}_topics",
|
|
|
|
"TaxonomyTopics")
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.install_taxo_topics(klass)
|
2007-03-17 13:13:25 +03:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2005-11-23 12:32:22 +03:00
|
|
|
class TaxonomyTopics < TaxonomyTopicsBase
|
2007-03-17 13:13:25 +03:00
|
|
|
def to_feed(feed, current)
|
2005-11-23 12:24:17 +03:00
|
|
|
if current.respond_to?(:taxo_topics)
|
2005-11-23 12:32:22 +03:00
|
|
|
topics = current.class::TaxonomyTopics.new
|
2005-11-23 12:24:17 +03:00
|
|
|
bag = topics.Bag
|
|
|
|
@resources.each do |resource|
|
|
|
|
bag.lis << RDF::Bag::Li.new(resource)
|
|
|
|
end
|
|
|
|
current.taxo_topics = topics
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class TaxonomyTopicsBase < Base
|
2005-11-23 12:24:17 +03:00
|
|
|
attr_reader :resources
|
2007-03-17 13:13:25 +03:00
|
|
|
def_array_element("resource")
|
|
|
|
remove_method :new_resource
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-23 12:32:22 +03:00
|
|
|
module TaxonomyTopicModel
|
2005-11-23 12:24:17 +03:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class_name = "TaxonomyTopics"
|
|
|
|
klass.def_classed_elements("#{TAXO_PREFIX}_topic", "value", class_name)
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
2007-08-05 07:03:05 +04:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
def self.install_taxo_topic(klass)
|
2007-03-17 13:13:25 +03:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2005-11-23 12:32:22 +03:00
|
|
|
class TaxonomyTopics < TaxonomyTopicsBase
|
|
|
|
class TaxonomyTopic < TaxonomyTopicBase
|
2005-11-23 12:24:17 +03:00
|
|
|
DublinCoreModel.install_dublin_core(self)
|
2005-11-23 12:32:22 +03:00
|
|
|
TaxonomyTopicsModel.install_taxo_topics(self)
|
2005-11-23 12:24:17 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def to_feed(feed, current)
|
2005-11-23 12:24:17 +03:00
|
|
|
if current.respond_to?(:taxo_topics)
|
2005-11-23 12:32:22 +03:00
|
|
|
topic = current.class::TaxonomyTopic.new(value)
|
2005-11-23 12:24:17 +03:00
|
|
|
topic.taxo_link = value
|
2007-03-17 13:13:25 +03:00
|
|
|
taxo_topics.to_feed(feed, topic) if taxo_topics
|
2005-11-23 12:24:17 +03:00
|
|
|
current.taxo_topics << topic
|
2007-03-17 13:13:25 +03:00
|
|
|
setup_other_elements(feed, topic)
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class TaxonomyTopicsBase < Base
|
2007-12-02 09:45:53 +03:00
|
|
|
def_array_element("topic", nil, "TaxonomyTopic")
|
|
|
|
alias_method(:new_taxo_topic, :new_topic) # For backward compatibility
|
2005-11-23 12:24:17 +03:00
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class TaxonomyTopicBase < Base
|
2005-11-23 12:24:17 +03:00
|
|
|
include DublinCoreModel
|
2005-11-23 12:32:22 +03:00
|
|
|
include TaxonomyTopicsModel
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
attr_accessor :value
|
|
|
|
add_need_initialize_variable("value")
|
|
|
|
alias_method(:taxo_link, :value)
|
|
|
|
alias_method(:taxo_link=, :value=)
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
def have_required_values?
|
|
|
|
@value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RSSBase
|
2005-11-23 12:32:22 +03:00
|
|
|
include TaxonomyTopicModel
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
class ChannelBase
|
2005-11-23 12:32:22 +03:00
|
|
|
include TaxonomyTopicsModel
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 12:24:17 +03:00
|
|
|
class ItemsBase
|
|
|
|
class ItemBase
|
2005-11-23 12:32:22 +03:00
|
|
|
include TaxonomyTopicsModel
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
makers.each do |maker|
|
|
|
|
maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
|
|
|
TaxonomyTopicModel.install_taxo_topic(self)
|
2005-11-23 12:24:17 +03:00
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
class Channel
|
2005-11-23 12:32:22 +03:00
|
|
|
TaxonomyTopicsModel.install_taxo_topics(self)
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
class Items
|
|
|
|
class Item
|
|
|
|
TaxonomyTopicsModel.install_taxo_topics(self)
|
|
|
|
end
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
EOC
|
2005-11-23 12:24:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|