1 | require "rss/1.0"
|
---|
2 |
|
---|
3 | require "rss/maker/base"
|
---|
4 |
|
---|
5 | module RSS
|
---|
6 | module Maker
|
---|
7 |
|
---|
8 | class RSS10 < RSSBase
|
---|
9 |
|
---|
10 | def initialize
|
---|
11 | super("1.0")
|
---|
12 | end
|
---|
13 |
|
---|
14 | private
|
---|
15 | def make_rss
|
---|
16 | RDF.new(@version, @encoding, @standalone)
|
---|
17 | end
|
---|
18 |
|
---|
19 | def setup_elements(rss)
|
---|
20 | setup_channel(rss)
|
---|
21 | setup_image(rss)
|
---|
22 | setup_items(rss)
|
---|
23 | setup_textinput(rss)
|
---|
24 | end
|
---|
25 |
|
---|
26 | class Channel < ChannelBase
|
---|
27 |
|
---|
28 | def to_rss(rss)
|
---|
29 | set = false
|
---|
30 | if @about
|
---|
31 | channel = RDF::Channel.new(@about)
|
---|
32 | set = setup_values(channel)
|
---|
33 | if set
|
---|
34 | channel.dc_dates.clear
|
---|
35 | rss.channel = channel
|
---|
36 | setup_items(rss)
|
---|
37 | setup_image(rss)
|
---|
38 | setup_textinput(rss)
|
---|
39 | setup_other_elements(rss)
|
---|
40 | end
|
---|
41 | end
|
---|
42 |
|
---|
43 | if (!@about or !set) and variable_is_set?
|
---|
44 | raise NotSetError.new("maker.channel", not_set_required_variables)
|
---|
45 | end
|
---|
46 | end
|
---|
47 |
|
---|
48 | def have_required_values?
|
---|
49 | @about and @title and @link and @description
|
---|
50 | end
|
---|
51 |
|
---|
52 | private
|
---|
53 | def setup_items(rss)
|
---|
54 | items = RDF::Channel::Items.new
|
---|
55 | seq = items.Seq
|
---|
56 | @maker.items.normalize.each do |item|
|
---|
57 | seq.lis << RDF::Channel::Items::Seq::Li.new(item.link)
|
---|
58 | end
|
---|
59 | rss.channel.items = items
|
---|
60 | end
|
---|
61 |
|
---|
62 | def setup_image(rss)
|
---|
63 | if @maker.image.have_required_values?
|
---|
64 | rss.channel.image = RDF::Channel::Image.new(@maker.image.url)
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | def setup_textinput(rss)
|
---|
69 | if @maker.textinput.have_required_values?
|
---|
70 | textinput = RDF::Channel::Textinput.new(@maker.textinput.link)
|
---|
71 | rss.channel.textinput = textinput
|
---|
72 | end
|
---|
73 | end
|
---|
74 |
|
---|
75 | def required_variable_names
|
---|
76 | %w(about title link description)
|
---|
77 | end
|
---|
78 |
|
---|
79 | class SkipDays < SkipDaysBase
|
---|
80 | def to_rss(*args)
|
---|
81 | end
|
---|
82 |
|
---|
83 | class Day < DayBase
|
---|
84 | end
|
---|
85 | end
|
---|
86 |
|
---|
87 | class SkipHours < SkipHoursBase
|
---|
88 | def to_rss(*args)
|
---|
89 | end
|
---|
90 |
|
---|
91 | class Hour < HourBase
|
---|
92 | end
|
---|
93 | end
|
---|
94 |
|
---|
95 | class Cloud < CloudBase
|
---|
96 | def to_rss(*args)
|
---|
97 | end
|
---|
98 | end
|
---|
99 |
|
---|
100 | class Categories < CategoriesBase
|
---|
101 | def to_rss(*args)
|
---|
102 | end
|
---|
103 |
|
---|
104 | class Category < CategoryBase
|
---|
105 | end
|
---|
106 | end
|
---|
107 | end
|
---|
108 |
|
---|
109 | class Image < ImageBase
|
---|
110 | def to_rss(rss)
|
---|
111 | if @url
|
---|
112 | image = RDF::Image.new(@url)
|
---|
113 | set = setup_values(image)
|
---|
114 | if set
|
---|
115 | rss.image = image
|
---|
116 | setup_other_elements(rss)
|
---|
117 | end
|
---|
118 | end
|
---|
119 | end
|
---|
120 |
|
---|
121 | def have_required_values?
|
---|
122 | @url and @title and link and @maker.channel.have_required_values?
|
---|
123 | end
|
---|
124 |
|
---|
125 | private
|
---|
126 | def variables
|
---|
127 | super + ["link"]
|
---|
128 | end
|
---|
129 | end
|
---|
130 |
|
---|
131 | class Items < ItemsBase
|
---|
132 | def to_rss(rss)
|
---|
133 | if rss.channel
|
---|
134 | normalize.each do |item|
|
---|
135 | item.to_rss(rss)
|
---|
136 | end
|
---|
137 | setup_other_elements(rss)
|
---|
138 | end
|
---|
139 | end
|
---|
140 |
|
---|
141 | class Item < ItemBase
|
---|
142 | def to_rss(rss)
|
---|
143 | if @link
|
---|
144 | item = RDF::Item.new(@link)
|
---|
145 | set = setup_values(item)
|
---|
146 | if set
|
---|
147 | item.dc_dates.clear
|
---|
148 | rss.items << item
|
---|
149 | setup_other_elements(rss)
|
---|
150 | end
|
---|
151 | end
|
---|
152 | end
|
---|
153 |
|
---|
154 | def have_required_values?
|
---|
155 | @title and @link
|
---|
156 | end
|
---|
157 |
|
---|
158 | class Guid < GuidBase
|
---|
159 | def to_rss(*args)
|
---|
160 | end
|
---|
161 | end
|
---|
162 |
|
---|
163 | class Enclosure < EnclosureBase
|
---|
164 | def to_rss(*args)
|
---|
165 | end
|
---|
166 | end
|
---|
167 |
|
---|
168 | class Source < SourceBase
|
---|
169 | def to_rss(*args)
|
---|
170 | end
|
---|
171 | end
|
---|
172 |
|
---|
173 | class Categories < CategoriesBase
|
---|
174 | def to_rss(*args)
|
---|
175 | end
|
---|
176 |
|
---|
177 | class Category < CategoryBase
|
---|
178 | end
|
---|
179 | end
|
---|
180 | end
|
---|
181 | end
|
---|
182 |
|
---|
183 | class Textinput < TextinputBase
|
---|
184 | def to_rss(rss)
|
---|
185 | if @link
|
---|
186 | textinput = RDF::Textinput.new(@link)
|
---|
187 | set = setup_values(textinput)
|
---|
188 | if set
|
---|
189 | rss.textinput = textinput
|
---|
190 | setup_other_elements(rss)
|
---|
191 | end
|
---|
192 | end
|
---|
193 | end
|
---|
194 |
|
---|
195 | def have_required_values?
|
---|
196 | @title and @description and @name and @link and
|
---|
197 | @maker.channel.have_required_values?
|
---|
198 | end
|
---|
199 | end
|
---|
200 | end
|
---|
201 |
|
---|
202 | add_maker(filename_to_version(__FILE__), RSS10)
|
---|
203 | end
|
---|
204 | end
|
---|