# frozen_string_literal: false
require_relative 'dublincore'
# The prefix for the Image XML namespace.
# The URI for the Image specification.
IMAGE_URI = 'http://purl.org/rss/1.0/modules/image/'
RDF.install_ns(IMAGE_PREFIX, IMAGE_URI)
# This constant holds strings which contain the names of
# image elements, with the appropriate prefix.
%w(item favicon).each do |name|
class_name = Utils.to_class_name(name)
BaseListener.install_class_name(IMAGE_URI, name, "Image#{class_name}")
IMAGE_ELEMENTS << "#{IMAGE_PREFIX}_#{name}"
def validate_one_tag_name(ignore_unknown_element, name, tags)
if !ignore_unknown_element
invalid = tags.find {|tag| tag != name}
raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
raise TooMuchTagError.new(name, tag_name) if tags.size > 1
def self.append_features(klass)
klass.install_have_child_element("item", IMAGE_URI, "?",
klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
class ImageItem < Element
install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
["about", ::RSS::RDF::URI, true],
["resource", ::RSS::RDF::URI, false],
].each do |name, uri, required|
install_get_attribute(name, uri, required, nil, nil,
"#{::RSS::RDF::PREFIX}:#{name}")
%w(width height).each do |tag|
full_name = "#{IMAGE_PREFIX}_#{tag}"
disp_name = "#{IMAGE_PREFIX}:#{tag}"
install_text_element(tag, IMAGE_URI, "?",
full_name, :integer, disp_name)
BaseListener.install_get_text_element(IMAGE_URI, tag, full_name)
alias width= image_width=
alias height= image_height=
alias height image_height
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(IMAGE_PREFIX)
def setup_maker_attributes(item)
item.resource = self.resource
def self.append_features(klass)
unless klass.class == Module
klass.install_have_child_element("favicon", IMAGE_URI, "?",
"#{IMAGE_PREFIX}_favicon")
klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
class ImageFavicon < Element
["about", ::RSS::RDF::URI, true, ::RSS::RDF::PREFIX],
["size", IMAGE_URI, true, IMAGE_PREFIX],
].each do |name, uri, required, prefix|
install_get_attribute(name, uri, required, nil, nil,
AVAILABLE_SIZES = %w(small medium large)
alias_method :set_size, :size=
if @do_validate and !new_value.nil?
new_value = new_value.strip
unless AVAILABLE_SIZES.include?(new_value)
attr_name = "#{IMAGE_PREFIX}:size"
raise NotAvailableValueError.new(full_name, new_value, attr_name)
if Utils.element_initialize_arguments?(args)
tag_name_with_prefix(IMAGE_PREFIX)
def setup_maker_attributes(favicon)
favicon.about = self.about
class Channel; include ImageFaviconModel; end
class Item; include ImageItemModel; end