1 | require 'rss/image'
|
---|
2 | require 'rss/maker/1.0'
|
---|
3 | require 'rss/maker/dublincore'
|
---|
4 |
|
---|
5 | module RSS
|
---|
6 | module Maker
|
---|
7 | module ImageItemModel
|
---|
8 | def self.append_features(klass)
|
---|
9 | super
|
---|
10 |
|
---|
11 | name = "#{RSS::IMAGE_PREFIX}_item"
|
---|
12 | klass.add_need_initialize_variable(name, "make_#{name}")
|
---|
13 | klass.add_other_element(name)
|
---|
14 | klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
|
---|
15 | attr_reader :#{name}
|
---|
16 | def setup_#{name}(rss, current)
|
---|
17 | if @#{name}
|
---|
18 | @#{name}.to_rss(rss, current)
|
---|
19 | end
|
---|
20 | end
|
---|
21 |
|
---|
22 | def make_#{name}
|
---|
23 | self.class::#{Utils.to_class_name(name)}.new(@maker)
|
---|
24 | end
|
---|
25 | EOC
|
---|
26 | end
|
---|
27 |
|
---|
28 | class ImageItemBase
|
---|
29 | include Base
|
---|
30 | include Maker::DublinCoreModel
|
---|
31 |
|
---|
32 | attr_accessor :about, :resource, :image_width, :image_height
|
---|
33 | add_need_initialize_variable("about")
|
---|
34 | add_need_initialize_variable("resource")
|
---|
35 | add_need_initialize_variable("image_width")
|
---|
36 | add_need_initialize_variable("image_height")
|
---|
37 | alias width= image_width=
|
---|
38 | alias width image_width
|
---|
39 | alias height= image_height=
|
---|
40 | alias height image_height
|
---|
41 |
|
---|
42 | def have_required_values?
|
---|
43 | @about
|
---|
44 | end
|
---|
45 | end
|
---|
46 | end
|
---|
47 |
|
---|
48 | module ImageFaviconModel
|
---|
49 | def self.append_features(klass)
|
---|
50 | super
|
---|
51 |
|
---|
52 | name = "#{RSS::IMAGE_PREFIX}_favicon"
|
---|
53 | klass.add_need_initialize_variable(name, "make_#{name}")
|
---|
54 | klass.add_other_element(name)
|
---|
55 | klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
|
---|
56 | attr_reader :#{name}
|
---|
57 | def setup_#{name}(rss, current)
|
---|
58 | if @#{name}
|
---|
59 | @#{name}.to_rss(rss, current)
|
---|
60 | end
|
---|
61 | end
|
---|
62 |
|
---|
63 | def make_#{name}
|
---|
64 | self.class::#{Utils.to_class_name(name)}.new(@maker)
|
---|
65 | end
|
---|
66 | EOC
|
---|
67 | end
|
---|
68 |
|
---|
69 | class ImageFaviconBase
|
---|
70 | include Base
|
---|
71 | include Maker::DublinCoreModel
|
---|
72 |
|
---|
73 | attr_accessor :about, :image_size
|
---|
74 | add_need_initialize_variable("about")
|
---|
75 | add_need_initialize_variable("image_size")
|
---|
76 | alias size image_size
|
---|
77 | alias size= image_size=
|
---|
78 |
|
---|
79 | def have_required_values?
|
---|
80 | @about and @image_size
|
---|
81 | end
|
---|
82 | end
|
---|
83 | end
|
---|
84 |
|
---|
85 | class ChannelBase; include Maker::ImageFaviconModel; end
|
---|
86 |
|
---|
87 | class ItemsBase
|
---|
88 | class ItemBase; include Maker::ImageItemModel; end
|
---|
89 | end
|
---|
90 |
|
---|
91 | class RSS10
|
---|
92 | class Items
|
---|
93 | class Item
|
---|
94 | class ImageItem < ImageItemBase
|
---|
95 | DublinCoreModel.install_dublin_core(self)
|
---|
96 | def to_rss(rss, current)
|
---|
97 | if @about
|
---|
98 | item = ::RSS::ImageItemModel::ImageItem.new(@about, @resource)
|
---|
99 | setup_values(item)
|
---|
100 | setup_other_elements(item)
|
---|
101 | current.image_item = item
|
---|
102 | end
|
---|
103 | end
|
---|
104 | end
|
---|
105 | end
|
---|
106 | end
|
---|
107 |
|
---|
108 | class Channel
|
---|
109 | class ImageFavicon < ImageFaviconBase
|
---|
110 | DublinCoreModel.install_dublin_core(self)
|
---|
111 | def to_rss(rss, current)
|
---|
112 | if @about and @image_size
|
---|
113 | args = [@about, @image_size]
|
---|
114 | favicon = ::RSS::ImageFaviconModel::ImageFavicon.new(*args)
|
---|
115 | setup_values(favicon)
|
---|
116 | setup_other_elements(favicon)
|
---|
117 | current.image_favicon = favicon
|
---|
118 | end
|
---|
119 | end
|
---|
120 | end
|
---|
121 | end
|
---|
122 | end
|
---|
123 |
|
---|
124 | class RSS09
|
---|
125 | class Items
|
---|
126 | class Item
|
---|
127 | class ImageItem < ImageItemBase
|
---|
128 | DublinCoreModel.install_dublin_core(self)
|
---|
129 | def to_rss(*args)
|
---|
130 | end
|
---|
131 | end
|
---|
132 | end
|
---|
133 | end
|
---|
134 |
|
---|
135 | class Channel
|
---|
136 | class ImageFavicon < ImageFaviconBase
|
---|
137 | DublinCoreModel.install_dublin_core(self)
|
---|
138 | def to_rss(*args)
|
---|
139 | end
|
---|
140 | end
|
---|
141 | end
|
---|
142 | end
|
---|
143 |
|
---|
144 | end
|
---|
145 | end
|
---|