2007-03-17 06:13:25 -04:00
|
|
|
require "rss/rss"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
module RSS
|
2013-11-09 00:56:09 -05:00
|
|
|
# The prefix for the Dublin Core XML namespace.
|
2004-10-16 00:51:15 -04:00
|
|
|
DC_PREFIX = 'dc'
|
2013-11-09 00:56:09 -05:00
|
|
|
# The URI of the Dublin Core specification.
|
2004-10-16 00:51:15 -04:00
|
|
|
DC_URI = "http://purl.org/dc/elements/1.1/"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
module BaseDublinCoreModel
|
|
|
|
def append_features(klass)
|
|
|
|
super
|
|
|
|
|
|
|
|
return if klass.instance_of?(Module)
|
|
|
|
DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
|
|
|
|
plural = plural_name || "#{name}s"
|
|
|
|
full_name = "#{DC_PREFIX}_#{name}"
|
|
|
|
full_plural_name = "#{DC_PREFIX}_#{plural}"
|
|
|
|
klass_name = "DublinCore#{Utils.to_class_name(name)}"
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.install_must_call_validator(DC_PREFIX, DC_URI)
|
|
|
|
klass.install_have_children_element(name, DC_URI, "*",
|
|
|
|
full_name, full_plural_name)
|
2005-04-05 02:42:03 -04:00
|
|
|
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
|
|
|
|
remove_method :#{full_name}
|
|
|
|
remove_method :#{full_name}=
|
|
|
|
remove_method :set_#{full_name}
|
|
|
|
|
|
|
|
def #{full_name}
|
|
|
|
@#{full_name}.first and @#{full_name}.first.value
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
def #{full_name}=(new_value)
|
|
|
|
@#{full_name}[0] = Utils.new_with_value_if_need(#{klass_name}, new_value)
|
|
|
|
end
|
|
|
|
alias set_#{full_name} #{full_name}=
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
|
2007-03-17 06:13:25 -04:00
|
|
|
if method_defined?(:date)
|
|
|
|
alias date_without_#{DC_PREFIX}_date= date=
|
|
|
|
|
|
|
|
def date=(value)
|
|
|
|
self.date_without_#{DC_PREFIX}_date = value
|
|
|
|
self.#{DC_PREFIX}_date = value
|
|
|
|
end
|
|
|
|
else
|
|
|
|
alias date #{DC_PREFIX}_date
|
|
|
|
alias date= #{DC_PREFIX}_date=
|
|
|
|
end
|
2007-02-11 21:52:32 -05:00
|
|
|
|
|
|
|
# For backward compatibility
|
|
|
|
alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
|
2005-04-05 02:42:03 -04:00
|
|
|
EOC
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
module DublinCoreModel
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
extend BaseModel
|
2005-04-05 02:42:03 -04:00
|
|
|
extend BaseDublinCoreModel
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
TEXT_ELEMENTS = {
|
|
|
|
"title" => nil,
|
|
|
|
"description" => nil,
|
|
|
|
"creator" => nil,
|
|
|
|
"subject" => nil,
|
|
|
|
"publisher" => nil,
|
|
|
|
"contributor" => nil,
|
|
|
|
"type" => nil,
|
|
|
|
"format" => nil,
|
|
|
|
"identifier" => nil,
|
|
|
|
"source" => nil,
|
|
|
|
"language" => nil,
|
|
|
|
"relation" => nil,
|
|
|
|
"coverage" => nil,
|
2007-02-11 21:52:32 -05:00
|
|
|
"rights" => "rights_list"
|
2005-04-05 02:42:03 -04:00
|
|
|
}
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
DATE_ELEMENTS = {
|
|
|
|
"date" => "w3cdtf",
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
ELEMENT_NAME_INFOS = DublinCoreModel::TEXT_ELEMENTS.to_a
|
2007-03-17 06:13:25 -04:00
|
|
|
DublinCoreModel::DATE_ELEMENTS.each do |name, |
|
2005-04-05 02:42:03 -04:00
|
|
|
ELEMENT_NAME_INFOS << [name, nil]
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
ELEMENTS = TEXT_ELEMENTS.keys + DATE_ELEMENTS.keys
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
ELEMENTS.each do |name, plural_name|
|
2005-04-05 02:42:03 -04:00
|
|
|
module_eval(<<-EOC, *get_file_and_line_from_caller(0))
|
2005-04-05 03:03:43 -04:00
|
|
|
class DublinCore#{Utils.to_class_name(name)} < Element
|
2005-04-05 02:42:03 -04:00
|
|
|
include RSS10
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
content_setup
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def required_prefix
|
|
|
|
DC_PREFIX
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
def required_uri
|
|
|
|
DC_URI
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
@tag_name = #{name.dump}
|
2005-04-05 02:42:03 -04:00
|
|
|
|
|
|
|
alias_method(:value, :content)
|
|
|
|
alias_method(:value=, :content=)
|
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.content = args[0]
|
|
|
|
end
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(DC_PREFIX)
|
|
|
|
end
|
|
|
|
|
|
|
|
def maker_target(target)
|
2005-04-05 03:03:43 -04:00
|
|
|
target.new_#{name}
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2004-02-03 09:01:42 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
def setup_maker_attributes(#{name})
|
|
|
|
#{name}.content = content
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
DATE_ELEMENTS.each do |name, type|
|
2007-03-17 06:13:25 -04:00
|
|
|
tag_name = "#{DC_PREFIX}:#{name}"
|
2005-04-05 02:42:03 -04:00
|
|
|
module_eval(<<-EOC, *get_file_and_line_from_caller(0))
|
|
|
|
class DublinCore#{Utils.to_class_name(name)} < Element
|
2005-04-05 03:03:43 -04:00
|
|
|
remove_method(:content=)
|
|
|
|
remove_method(:value=)
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
date_writer("content", #{type.dump}, #{tag_name.dump})
|
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
alias_method(:value=, :content=)
|
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
# For backward compatibility
|
|
|
|
DublincoreModel = DublinCoreModel
|
2004-03-02 11:21:11 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
DublinCoreModel::ELEMENTS.each do |name|
|
|
|
|
class_name = Utils.to_class_name(name)
|
|
|
|
BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
|
|
|
|
require 'rss/dublincore/1.0'
|
|
|
|
require 'rss/dublincore/2.0'
|
|
|
|
require 'rss/dublincore/atom'
|