2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/1.0"
|
2005-11-17 03:56:03 -05:00
|
|
|
require "rss/dublincore"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
module RSS
|
2013-11-09 00:56:09 -05:00
|
|
|
# The prefix for the Taxonomy XML namespace.
|
2004-10-16 00:51:15 -04:00
|
|
|
TAXO_PREFIX = "taxo"
|
2013-11-09 00:56:09 -05:00
|
|
|
# The URI for the specification of the Taxonomy XML namespace.
|
2005-11-17 03:56:03 -05:00
|
|
|
TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
RDF.install_ns(TAXO_PREFIX, TAXO_URI)
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2013-11-09 00:56:09 -05:00
|
|
|
# The listing of all the taxonomy elements, with the appropriate namespace.
|
2004-10-16 00:51:15 -04:00
|
|
|
TAXO_ELEMENTS = []
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(link).each do |name|
|
|
|
|
full_name = "#{TAXO_PREFIX}_#{name}"
|
2007-03-17 06:13:25 -04:00
|
|
|
BaseListener.install_get_text_element(TAXO_URI, name, full_name)
|
2005-11-17 03:56:03 -05:00
|
|
|
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(topic topics).each do |name|
|
|
|
|
class_name = Utils.to_class_name(name)
|
2005-11-23 04:32:22 -05:00
|
|
|
BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
|
2005-04-05 03:03:43 -04:00
|
|
|
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2005-11-17 03:56:03 -05:00
|
|
|
|
2005-11-23 04:32:22 -05:00
|
|
|
module TaxonomyTopicsModel
|
2005-11-17 03:56:03 -05:00
|
|
|
extend BaseModel
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
|
|
|
|
%w(topics).each do |name|
|
|
|
|
klass.install_have_child_element(name, TAXO_URI, "?",
|
|
|
|
"#{TAXO_PREFIX}_#{name}")
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-23 04:32:22 -05:00
|
|
|
class TaxonomyTopics < Element
|
2005-11-17 03:56:03 -05:00
|
|
|
include RSS10
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
Bag = ::RSS::RDF::Bag
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def required_prefix
|
|
|
|
TAXO_PREFIX
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
def required_uri
|
|
|
|
TAXO_URI
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag_name = "topics"
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_child_element("Bag", RDF::URI, nil)
|
|
|
|
install_must_call_validator('rdf', RDF::URI)
|
2005-11-17 03:56:03 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.Bag = args[0]
|
|
|
|
end
|
|
|
|
self.Bag ||= Bag.new
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(TAXO_PREFIX)
|
|
|
|
end
|
2005-11-23 04:24:17 -05:00
|
|
|
|
|
|
|
def maker_target(target)
|
|
|
|
target.taxo_topics
|
|
|
|
end
|
2005-11-17 03:56:03 -05:00
|
|
|
|
2005-11-17 04:01:22 -05:00
|
|
|
def resources
|
|
|
|
if @Bag
|
|
|
|
@Bag.lis.collect do |li|
|
|
|
|
li.resource
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-23 04:32:22 -05:00
|
|
|
module TaxonomyTopicModel
|
2005-11-17 03:56:03 -05:00
|
|
|
extend BaseModel
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
var_name = "#{TAXO_PREFIX}_topic"
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
|
|
|
|
2005-11-23 04:32:22 -05:00
|
|
|
class TaxonomyTopic < Element
|
2005-11-17 03:56:03 -05:00
|
|
|
include RSS10
|
|
|
|
|
|
|
|
include DublinCoreModel
|
2005-11-23 04:32:22 -05:00
|
|
|
include TaxonomyTopicsModel
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
class << self
|
|
|
|
def required_prefix
|
|
|
|
TAXO_PREFIX
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:56:03 -05:00
|
|
|
def required_uri
|
|
|
|
TAXO_URI
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag_name = "topic"
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
|
|
|
|
"#{RDF::PREFIX}:about")
|
|
|
|
install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
|
|
|
end
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(TAXO_PREFIX)
|
|
|
|
end
|
|
|
|
|
2005-11-23 04:24:17 -05:00
|
|
|
def maker_target(target)
|
|
|
|
target.new_taxo_topic
|
|
|
|
end
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RDF
|
2005-11-23 04:32:22 -05:00
|
|
|
include TaxonomyTopicModel
|
2005-11-17 03:56:03 -05:00
|
|
|
class Channel
|
2005-11-23 04:32:22 -05:00
|
|
|
include TaxonomyTopicsModel
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
2005-11-23 04:32:22 -05:00
|
|
|
class Item; include TaxonomyTopicsModel; end
|
2005-11-17 03:56:03 -05:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|