2004-10-31 09:14:21 -05:00
|
|
|
require 'rss/dublincore'
|
|
|
|
require 'rss/maker/1.0'
|
|
|
|
|
|
|
|
module RSS
|
|
|
|
module Maker
|
|
|
|
module DublinCoreModel
|
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
2005-04-05 02:42:03 -04:00
|
|
|
::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
|
|
|
|
plural_name ||= "#{name}s"
|
|
|
|
full_name = "#{RSS::DC_PREFIX}_#{name}"
|
|
|
|
full_plural_name = "#{RSS::DC_PREFIX}_#{plural_name}"
|
|
|
|
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
|
2007-08-04 23:03:05 -04:00
|
|
|
klass.def_classed_elements(full_name, "value", plural_klass_name,
|
|
|
|
full_plural_name, name)
|
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2007-03-17 06:13:25 -04:00
|
|
|
def new_#{full_name}(value=nil)
|
2007-08-04 23:03:05 -04:00
|
|
|
_#{full_name} = #{full_plural_name}.new_#{name}
|
|
|
|
_#{full_name}.value = value
|
2007-03-17 06:13:25 -04:00
|
|
|
if block_given?
|
2007-08-04 23:03:05 -04:00
|
|
|
yield _#{full_name}
|
2007-03-17 06:13:25 -04:00
|
|
|
else
|
2007-08-04 23:03:05 -04:00
|
|
|
_#{full_name}
|
2007-03-17 06:13:25 -04:00
|
|
|
end
|
|
|
|
end
|
2007-08-04 23:03:05 -04:00
|
|
|
EOC
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2007-02-11 21:52:32 -05:00
|
|
|
|
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
|
|
|
# For backward compatibility
|
|
|
|
alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
|
2007-08-04 23:03:05 -04:00
|
|
|
EOC
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
|
|
|
|
plural_name ||= "#{name}s"
|
2007-08-04 23:03:05 -04:00
|
|
|
full_name ||= "#{DC_PREFIX}_#{name}"
|
|
|
|
full_plural_name ||= "#{DC_PREFIX}_#{plural_name}"
|
2005-04-05 02:42:03 -04:00
|
|
|
klass_name = Utils.to_class_name(name)
|
2007-03-17 06:13:25 -04:00
|
|
|
full_klass_name = "DublinCore#{klass_name}"
|
2005-04-05 02:42:03 -04:00
|
|
|
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
|
2007-08-04 23:03:05 -04:00
|
|
|
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
|
|
|
class #{plural_klass_name}Base < Base
|
|
|
|
def_array_element(#{name.dump}, #{full_plural_name.dump},
|
|
|
|
#{full_klass_name.dump})
|
2005-04-05 02:42:03 -04:00
|
|
|
|
2007-08-04 23:03:05 -04:00
|
|
|
class #{full_klass_name}Base < Base
|
2005-04-05 02:42:03 -04:00
|
|
|
attr_accessor :value
|
|
|
|
add_need_initialize_variable("value")
|
|
|
|
alias_method(:content, :value)
|
|
|
|
alias_method(:content=, :value=)
|
|
|
|
|
|
|
|
def have_required_values?
|
|
|
|
@value
|
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
|
|
|
|
def to_feed(feed, current)
|
2007-08-04 23:03:05 -04:00
|
|
|
if value and current.respond_to?(:#{full_name})
|
2007-03-17 06:13:25 -04:00
|
|
|
new_item = current.class::#{full_klass_name}.new(value)
|
2007-08-04 23:03:05 -04:00
|
|
|
current.#{full_plural_name} << new_item
|
2007-03-17 06:13:25 -04:00
|
|
|
end
|
|
|
|
end
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2007-08-04 23:03:05 -04:00
|
|
|
#{klass_name}Base = #{full_klass_name}Base
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.install_dublin_core(klass)
|
|
|
|
::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
|
|
|
|
plural_name ||= "#{name}s"
|
|
|
|
klass_name = Utils.to_class_name(name)
|
2007-08-04 23:03:05 -04:00
|
|
|
full_klass_name = "DublinCore#{klass_name}"
|
2005-04-05 02:42:03 -04:00
|
|
|
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2005-04-05 02:42:03 -04:00
|
|
|
class #{plural_klass_name} < #{plural_klass_name}Base
|
2007-08-04 23:03:05 -04:00
|
|
|
class #{full_klass_name} < #{full_klass_name}Base
|
2004-10-31 09:14:21 -05:00
|
|
|
end
|
2007-08-04 23:03:05 -04:00
|
|
|
#{klass_name} = #{full_klass_name}
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2004-10-31 09:14:21 -05:00
|
|
|
EOC
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-03 01:43:18 -05:00
|
|
|
class ChannelBase
|
|
|
|
include DublinCoreModel
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-03 01:43:18 -05:00
|
|
|
class ImageBase; include DublinCoreModel; end
|
|
|
|
class ItemsBase
|
|
|
|
class ItemBase
|
|
|
|
include DublinCoreModel
|
2004-10-31 09:14:21 -05:00
|
|
|
end
|
|
|
|
end
|
2004-11-03 01:43:18 -05:00
|
|
|
class TextinputBase; include DublinCoreModel; end
|
2005-04-05 02:42:03 -04:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
makers.each do |maker|
|
|
|
|
maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
|
|
|
class Channel
|
2005-04-05 02:42:03 -04:00
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
class Image
|
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
2005-04-05 02:42:03 -04:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
class Items
|
|
|
|
class Item
|
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
|
|
|
end
|
2005-04-05 02:42:03 -04:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
class Textinput
|
2005-04-05 02:42:03 -04:00
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
EOC
|
2005-04-05 02:42:03 -04:00
|
|
|
end
|
2004-10-31 09:14:21 -05:00
|
|
|
end
|
|
|
|
end
|