2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2005-02-03 18:31:57 +03:00
|
|
|
require 'rss/image'
|
|
|
|
require 'rss/maker/1.0'
|
|
|
|
require 'rss/maker/dublincore'
|
|
|
|
|
|
|
|
module RSS
|
|
|
|
module Maker
|
|
|
|
module ImageItemModel
|
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
|
|
|
name = "#{RSS::IMAGE_PREFIX}_item"
|
2007-08-05 07:03:05 +04:00
|
|
|
klass.def_classed_element(name)
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def self.install_image_item(klass)
|
2011-05-19 01:19:18 +04:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2007-03-17 13:13:25 +03:00
|
|
|
class ImageItem < ImageItemBase
|
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
2011-05-19 04:07:25 +04:00
|
|
|
EOC
|
2007-03-17 13:13:25 +03:00
|
|
|
end
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class ImageItemBase < Base
|
2005-02-03 18:31:57 +03:00
|
|
|
include Maker::DublinCoreModel
|
|
|
|
|
|
|
|
attr_accessor :about, :resource, :image_width, :image_height
|
2005-04-05 10:42:03 +04:00
|
|
|
add_need_initialize_variable("about")
|
|
|
|
add_need_initialize_variable("resource")
|
|
|
|
add_need_initialize_variable("image_width")
|
|
|
|
add_need_initialize_variable("image_height")
|
2005-02-03 18:31:57 +03:00
|
|
|
alias width= image_width=
|
2011-05-19 04:07:25 +04:00
|
|
|
alias width image_width
|
2005-02-03 18:31:57 +03:00
|
|
|
alias height= image_height=
|
2011-05-19 04:07:25 +04:00
|
|
|
alias height image_height
|
2005-02-03 18:31:57 +03:00
|
|
|
|
|
|
|
def have_required_values?
|
|
|
|
@about
|
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
|
|
|
|
def to_feed(feed, current)
|
|
|
|
if current.respond_to?(:image_item=) and have_required_values?
|
|
|
|
item = current.class::ImageItem.new
|
|
|
|
setup_values(item)
|
|
|
|
setup_other_elements(item)
|
|
|
|
current.image_item = item
|
|
|
|
end
|
|
|
|
end
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ImageFaviconModel
|
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
|
|
|
|
|
|
|
name = "#{RSS::IMAGE_PREFIX}_favicon"
|
2007-08-05 07:03:05 +04:00
|
|
|
klass.def_classed_element(name)
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
def self.install_image_favicon(klass)
|
2011-05-19 01:19:18 +04:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2007-03-17 13:13:25 +03:00
|
|
|
class ImageFavicon < ImageFaviconBase
|
|
|
|
DublinCoreModel.install_dublin_core(self)
|
|
|
|
end
|
2007-08-05 07:03:05 +04:00
|
|
|
EOC
|
2007-03-17 13:13:25 +03:00
|
|
|
end
|
|
|
|
|
2007-08-05 07:03:05 +04:00
|
|
|
class ImageFaviconBase < Base
|
2005-02-03 18:31:57 +03:00
|
|
|
include Maker::DublinCoreModel
|
|
|
|
|
|
|
|
attr_accessor :about, :image_size
|
2005-04-05 10:42:03 +04:00
|
|
|
add_need_initialize_variable("about")
|
|
|
|
add_need_initialize_variable("image_size")
|
2005-02-03 18:31:57 +03:00
|
|
|
alias size image_size
|
|
|
|
alias size= image_size=
|
|
|
|
|
2011-05-19 04:07:25 +04:00
|
|
|
def have_required_values?
|
|
|
|
@about and @image_size
|
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
|
|
|
|
def to_feed(feed, current)
|
|
|
|
if current.respond_to?(:image_favicon=) and have_required_values?
|
|
|
|
favicon = current.class::ImageFavicon.new
|
|
|
|
setup_values(favicon)
|
|
|
|
setup_other_elements(favicon)
|
|
|
|
current.image_favicon = favicon
|
|
|
|
end
|
|
|
|
end
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ChannelBase; include Maker::ImageFaviconModel; end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-02-03 18:31:57 +03:00
|
|
|
class ItemsBase
|
|
|
|
class ItemBase; include Maker::ImageItemModel; end
|
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
makers.each do |maker|
|
|
|
|
maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
|
|
|
class Channel
|
|
|
|
ImageFaviconModel.install_image_favicon(self)
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
|
2007-03-17 13:13:25 +03:00
|
|
|
class Items
|
|
|
|
class Item
|
|
|
|
ImageItemModel.install_image_item(self)
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
end
|
2007-03-17 13:13:25 +03:00
|
|
|
EOC
|
2005-02-03 18:31:57 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|