rss 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +88 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rss.rb +92 -0
- data/lib/rss/0.9.rb +462 -0
- data/lib/rss/1.0.rb +485 -0
- data/lib/rss/2.0.rb +143 -0
- data/lib/rss/atom.rb +1025 -0
- data/lib/rss/content.rb +34 -0
- data/lib/rss/content/1.0.rb +10 -0
- data/lib/rss/content/2.0.rb +12 -0
- data/lib/rss/converter.rb +171 -0
- data/lib/rss/dublincore.rb +164 -0
- data/lib/rss/dublincore/1.0.rb +13 -0
- data/lib/rss/dublincore/2.0.rb +13 -0
- data/lib/rss/dublincore/atom.rb +17 -0
- data/lib/rss/image.rb +198 -0
- data/lib/rss/itunes.rb +413 -0
- data/lib/rss/maker.rb +79 -0
- data/lib/rss/maker/0.9.rb +509 -0
- data/lib/rss/maker/1.0.rb +436 -0
- data/lib/rss/maker/2.0.rb +224 -0
- data/lib/rss/maker/atom.rb +173 -0
- data/lib/rss/maker/base.rb +945 -0
- data/lib/rss/maker/content.rb +22 -0
- data/lib/rss/maker/dublincore.rb +122 -0
- data/lib/rss/maker/entry.rb +164 -0
- data/lib/rss/maker/feed.rb +427 -0
- data/lib/rss/maker/image.rb +112 -0
- data/lib/rss/maker/itunes.rb +243 -0
- data/lib/rss/maker/slash.rb +34 -0
- data/lib/rss/maker/syndication.rb +19 -0
- data/lib/rss/maker/taxonomy.rb +119 -0
- data/lib/rss/maker/trackback.rb +62 -0
- data/lib/rss/parser.rb +589 -0
- data/lib/rss/rexmlparser.rb +50 -0
- data/lib/rss/rss.rb +1346 -0
- data/lib/rss/slash.rb +52 -0
- data/lib/rss/syndication.rb +69 -0
- data/lib/rss/taxonomy.rb +148 -0
- data/lib/rss/trackback.rb +291 -0
- data/lib/rss/utils.rb +200 -0
- data/lib/rss/xml-stylesheet.rb +106 -0
- data/lib/rss/xml.rb +72 -0
- data/lib/rss/xmlparser.rb +95 -0
- data/lib/rss/xmlscanner.rb +122 -0
- data/rss.gemspec +38 -0
- metadata +138 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
require_relative "../atom"
|
3
|
+
|
4
|
+
require_relative "base"
|
5
|
+
|
6
|
+
module RSS
|
7
|
+
module Maker
|
8
|
+
module AtomPersons
|
9
|
+
module_function
|
10
|
+
def def_atom_persons(klass, name, maker_name, plural=nil)
|
11
|
+
plural ||= "#{name}s"
|
12
|
+
klass_name = Utils.to_class_name(name)
|
13
|
+
plural_klass_name = Utils.to_class_name(plural)
|
14
|
+
|
15
|
+
klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
16
|
+
class #{plural_klass_name} < #{plural_klass_name}Base
|
17
|
+
class #{klass_name} < #{klass_name}Base
|
18
|
+
def to_feed(feed, current)
|
19
|
+
#{name} = feed.class::#{klass_name}.new
|
20
|
+
set = setup_values(#{name})
|
21
|
+
unless set
|
22
|
+
raise NotSetError.new(#{maker_name.dump},
|
23
|
+
not_set_required_variables)
|
24
|
+
end
|
25
|
+
current.#{plural} << #{name}
|
26
|
+
set_parent(#{name}, current)
|
27
|
+
setup_other_elements(#{name})
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def required_variable_names
|
32
|
+
%w(name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
EOC
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module AtomTextConstruct
|
41
|
+
class << self
|
42
|
+
def def_atom_text_construct(klass, name, maker_name, klass_name=nil,
|
43
|
+
atom_klass_name=nil)
|
44
|
+
klass_name ||= Utils.to_class_name(name)
|
45
|
+
atom_klass_name ||= Utils.to_class_name(name)
|
46
|
+
|
47
|
+
klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
48
|
+
class #{klass_name} < #{klass_name}Base
|
49
|
+
include #{self.name}
|
50
|
+
def to_feed(feed, current)
|
51
|
+
#{name} = current.class::#{atom_klass_name}.new
|
52
|
+
if setup_values(#{name})
|
53
|
+
current.#{name} = #{name}
|
54
|
+
set_parent(#{name}, current)
|
55
|
+
setup_other_elements(feed)
|
56
|
+
elsif variable_is_set?
|
57
|
+
raise NotSetError.new(#{maker_name.dump},
|
58
|
+
not_set_required_variables)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
EOC
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def required_variable_names
|
68
|
+
if type == "xhtml"
|
69
|
+
%w(xml_content)
|
70
|
+
else
|
71
|
+
%w(content)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def variables
|
76
|
+
if type == "xhtml"
|
77
|
+
super + %w(xhtml)
|
78
|
+
else
|
79
|
+
super
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
module AtomCategory
|
85
|
+
def to_feed(feed, current)
|
86
|
+
category = feed.class::Category.new
|
87
|
+
set = setup_values(category)
|
88
|
+
if set
|
89
|
+
current.categories << category
|
90
|
+
set_parent(category, current)
|
91
|
+
setup_other_elements(feed)
|
92
|
+
else
|
93
|
+
raise NotSetError.new(self.class.not_set_name,
|
94
|
+
not_set_required_variables)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
def required_variable_names
|
100
|
+
%w(term)
|
101
|
+
end
|
102
|
+
|
103
|
+
def variables
|
104
|
+
super + ["term", "scheme"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module AtomLink
|
109
|
+
def to_feed(feed, current)
|
110
|
+
link = feed.class::Link.new
|
111
|
+
set = setup_values(link)
|
112
|
+
if set
|
113
|
+
current.links << link
|
114
|
+
set_parent(link, current)
|
115
|
+
setup_other_elements(feed)
|
116
|
+
else
|
117
|
+
raise NotSetError.new(self.class.not_set_name,
|
118
|
+
not_set_required_variables)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
def required_variable_names
|
124
|
+
%w(href)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module AtomGenerator
|
129
|
+
def to_feed(feed, current)
|
130
|
+
generator = current.class::Generator.new
|
131
|
+
if setup_values(generator)
|
132
|
+
current.generator = generator
|
133
|
+
set_parent(generator, current)
|
134
|
+
setup_other_elements(feed)
|
135
|
+
elsif variable_is_set?
|
136
|
+
raise NotSetError.new(self.class.not_set_name,
|
137
|
+
not_set_required_variables)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
def required_variable_names
|
143
|
+
%w(content)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
module AtomLogo
|
148
|
+
def to_feed(feed, current)
|
149
|
+
logo = current.class::Logo.new
|
150
|
+
class << logo
|
151
|
+
alias_method(:uri=, :content=)
|
152
|
+
end
|
153
|
+
set = setup_values(logo)
|
154
|
+
class << logo
|
155
|
+
remove_method(:uri=)
|
156
|
+
end
|
157
|
+
if set
|
158
|
+
current.logo = logo
|
159
|
+
set_parent(logo, current)
|
160
|
+
setup_other_elements(feed)
|
161
|
+
elsif variable_is_set?
|
162
|
+
raise NotSetError.new(self.class.not_set_name,
|
163
|
+
not_set_required_variables)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
def required_variable_names
|
169
|
+
%w(uri)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,945 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
require_relative '../rss'
|
5
|
+
|
6
|
+
module RSS
|
7
|
+
module Maker
|
8
|
+
class Base
|
9
|
+
extend Utils::InheritedReader
|
10
|
+
|
11
|
+
OTHER_ELEMENTS = []
|
12
|
+
NEED_INITIALIZE_VARIABLES = []
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def other_elements
|
16
|
+
inherited_array_reader("OTHER_ELEMENTS")
|
17
|
+
end
|
18
|
+
def need_initialize_variables
|
19
|
+
inherited_array_reader("NEED_INITIALIZE_VARIABLES")
|
20
|
+
end
|
21
|
+
|
22
|
+
def inherited_base
|
23
|
+
::RSS::Maker::Base
|
24
|
+
end
|
25
|
+
|
26
|
+
def inherited(subclass)
|
27
|
+
subclass.const_set(:OTHER_ELEMENTS, [])
|
28
|
+
subclass.const_set(:NEED_INITIALIZE_VARIABLES, [])
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_other_element(variable_name)
|
32
|
+
self::OTHER_ELEMENTS << variable_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_need_initialize_variable(variable_name, init_value=nil,
|
36
|
+
&init_block)
|
37
|
+
init_value ||= init_block
|
38
|
+
self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
|
39
|
+
end
|
40
|
+
|
41
|
+
def def_array_element(name, plural=nil, klass_name=nil)
|
42
|
+
include Enumerable
|
43
|
+
extend Forwardable
|
44
|
+
|
45
|
+
plural ||= "#{name}s"
|
46
|
+
klass_name ||= Utils.to_class_name(name)
|
47
|
+
def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last)
|
48
|
+
def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
|
49
|
+
def_delegators("@#{plural}", :each, :size, :empty?, :clear)
|
50
|
+
|
51
|
+
add_need_initialize_variable(plural) {[]}
|
52
|
+
|
53
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
54
|
+
def new_#{name}
|
55
|
+
#{name} = self.class::#{klass_name}.new(@maker)
|
56
|
+
@#{plural} << #{name}
|
57
|
+
if block_given?
|
58
|
+
yield #{name}
|
59
|
+
else
|
60
|
+
#{name}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
alias new_child new_#{name}
|
64
|
+
|
65
|
+
def to_feed(*args)
|
66
|
+
@#{plural}.each do |#{name}|
|
67
|
+
#{name}.to_feed(*args)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def replace(elements)
|
72
|
+
@#{plural}.replace(elements.to_a)
|
73
|
+
end
|
74
|
+
EOC
|
75
|
+
end
|
76
|
+
|
77
|
+
def def_classed_element_without_accessor(name, class_name=nil)
|
78
|
+
class_name ||= Utils.to_class_name(name)
|
79
|
+
add_other_element(name)
|
80
|
+
add_need_initialize_variable(name) do |object|
|
81
|
+
object.send("make_#{name}")
|
82
|
+
end
|
83
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
84
|
+
private
|
85
|
+
def setup_#{name}(feed, current)
|
86
|
+
@#{name}.to_feed(feed, current)
|
87
|
+
end
|
88
|
+
|
89
|
+
def make_#{name}
|
90
|
+
self.class::#{class_name}.new(@maker)
|
91
|
+
end
|
92
|
+
EOC
|
93
|
+
end
|
94
|
+
|
95
|
+
def def_classed_element(name, class_name=nil, attribute_name=nil)
|
96
|
+
def_classed_element_without_accessor(name, class_name)
|
97
|
+
if attribute_name
|
98
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
99
|
+
def #{name}
|
100
|
+
if block_given?
|
101
|
+
yield(@#{name})
|
102
|
+
else
|
103
|
+
@#{name}.#{attribute_name}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def #{name}=(new_value)
|
108
|
+
@#{name}.#{attribute_name} = new_value
|
109
|
+
end
|
110
|
+
EOC
|
111
|
+
else
|
112
|
+
attr_reader name
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def def_classed_elements(name, attribute, plural_class_name=nil,
|
117
|
+
plural_name=nil, new_name=nil)
|
118
|
+
plural_name ||= "#{name}s"
|
119
|
+
new_name ||= name
|
120
|
+
def_classed_element(plural_name, plural_class_name)
|
121
|
+
local_variable_name = "_#{name}"
|
122
|
+
new_value_variable_name = "new_value"
|
123
|
+
additional_setup_code = nil
|
124
|
+
if block_given?
|
125
|
+
additional_setup_code = yield(local_variable_name,
|
126
|
+
new_value_variable_name)
|
127
|
+
end
|
128
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
129
|
+
def #{name}
|
130
|
+
#{local_variable_name} = #{plural_name}.first
|
131
|
+
#{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
|
132
|
+
end
|
133
|
+
|
134
|
+
def #{name}=(#{new_value_variable_name})
|
135
|
+
#{local_variable_name} =
|
136
|
+
#{plural_name}.first || #{plural_name}.new_#{new_name}
|
137
|
+
#{additional_setup_code}
|
138
|
+
#{local_variable_name}.#{attribute} = #{new_value_variable_name}
|
139
|
+
end
|
140
|
+
EOC
|
141
|
+
end
|
142
|
+
|
143
|
+
def def_other_element(name)
|
144
|
+
attr_accessor name
|
145
|
+
def_other_element_without_accessor(name)
|
146
|
+
end
|
147
|
+
|
148
|
+
def def_other_element_without_accessor(name)
|
149
|
+
add_need_initialize_variable(name)
|
150
|
+
add_other_element(name)
|
151
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
152
|
+
def setup_#{name}(feed, current)
|
153
|
+
if !@#{name}.nil? and current.respond_to?(:#{name}=)
|
154
|
+
current.#{name} = @#{name}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
EOC
|
158
|
+
end
|
159
|
+
|
160
|
+
def def_csv_element(name, type=nil)
|
161
|
+
def_other_element_without_accessor(name)
|
162
|
+
attr_reader(name)
|
163
|
+
converter = ""
|
164
|
+
if type == :integer
|
165
|
+
converter = "{|v| Integer(v)}"
|
166
|
+
end
|
167
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
168
|
+
def #{name}=(value)
|
169
|
+
@#{name} = Utils::CSV.parse(value)#{converter}
|
170
|
+
end
|
171
|
+
EOC
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
attr_reader :maker
|
176
|
+
def initialize(maker)
|
177
|
+
@maker = maker
|
178
|
+
@default_values_are_set = false
|
179
|
+
initialize_variables
|
180
|
+
end
|
181
|
+
|
182
|
+
def have_required_values?
|
183
|
+
not_set_required_variables.empty?
|
184
|
+
end
|
185
|
+
|
186
|
+
def variable_is_set?
|
187
|
+
variables.any? {|var| not __send__(var).nil?}
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
def initialize_variables
|
192
|
+
self.class.need_initialize_variables.each do |variable_name, init_value|
|
193
|
+
if init_value.nil?
|
194
|
+
value = nil
|
195
|
+
else
|
196
|
+
if init_value.respond_to?(:call)
|
197
|
+
value = init_value.call(self)
|
198
|
+
elsif init_value.is_a?(String)
|
199
|
+
# just for backward compatibility
|
200
|
+
value = instance_eval(init_value, __FILE__, __LINE__)
|
201
|
+
else
|
202
|
+
value = init_value
|
203
|
+
end
|
204
|
+
end
|
205
|
+
instance_variable_set("@#{variable_name}", value)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def setup_other_elements(feed, current=nil)
|
210
|
+
current ||= current_element(feed)
|
211
|
+
self.class.other_elements.each do |element|
|
212
|
+
__send__("setup_#{element}", feed, current)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def current_element(feed)
|
217
|
+
feed
|
218
|
+
end
|
219
|
+
|
220
|
+
def set_default_values(&block)
|
221
|
+
return yield if @default_values_are_set
|
222
|
+
|
223
|
+
begin
|
224
|
+
@default_values_are_set = true
|
225
|
+
_set_default_values(&block)
|
226
|
+
ensure
|
227
|
+
@default_values_are_set = false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def _set_default_values(&block)
|
232
|
+
yield
|
233
|
+
end
|
234
|
+
|
235
|
+
def setup_values(target)
|
236
|
+
set = false
|
237
|
+
if have_required_values?
|
238
|
+
variables.each do |var|
|
239
|
+
setter = "#{var}="
|
240
|
+
if target.respond_to?(setter)
|
241
|
+
value = __send__(var)
|
242
|
+
unless value.nil?
|
243
|
+
target.__send__(setter, value)
|
244
|
+
set = true
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
set
|
250
|
+
end
|
251
|
+
|
252
|
+
def set_parent(target, parent)
|
253
|
+
target.parent = parent if target.class.need_parent?
|
254
|
+
end
|
255
|
+
|
256
|
+
def variables
|
257
|
+
self.class.need_initialize_variables.find_all do |name, init|
|
258
|
+
# init == "nil" is just for backward compatibility
|
259
|
+
init.nil? or init == "nil"
|
260
|
+
end.collect do |name, init|
|
261
|
+
name
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def not_set_required_variables
|
266
|
+
required_variable_names.find_all do |var|
|
267
|
+
__send__(var).nil?
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def required_variables_are_set?
|
272
|
+
required_variable_names.each do |var|
|
273
|
+
return false if __send__(var).nil?
|
274
|
+
end
|
275
|
+
true
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
module AtomPersonConstructBase
|
280
|
+
def self.append_features(klass)
|
281
|
+
super
|
282
|
+
|
283
|
+
klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
284
|
+
%w(name uri email).each do |element|
|
285
|
+
attr_accessor element
|
286
|
+
add_need_initialize_variable(element)
|
287
|
+
end
|
288
|
+
EOC
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
module AtomTextConstructBase
|
293
|
+
module EnsureXMLContent
|
294
|
+
class << self
|
295
|
+
def included(base)
|
296
|
+
super
|
297
|
+
base.class_eval do
|
298
|
+
%w(type content xml_content).each do |element|
|
299
|
+
attr_reader element
|
300
|
+
attr_writer element if element != "xml_content"
|
301
|
+
add_need_initialize_variable(element)
|
302
|
+
end
|
303
|
+
|
304
|
+
alias_method(:xhtml, :xml_content)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def ensure_xml_content(content)
|
310
|
+
xhtml_uri = ::RSS::Atom::XHTML_URI
|
311
|
+
unless content.is_a?(RSS::XML::Element) and
|
312
|
+
["div", xhtml_uri] == [content.name, content.uri]
|
313
|
+
children = content
|
314
|
+
children = [children] unless content.is_a?(Array)
|
315
|
+
children = set_xhtml_uri_as_default_uri(children)
|
316
|
+
content = RSS::XML::Element.new("div", nil, xhtml_uri,
|
317
|
+
{"xmlns" => xhtml_uri},
|
318
|
+
children)
|
319
|
+
end
|
320
|
+
content
|
321
|
+
end
|
322
|
+
|
323
|
+
def xml_content=(content)
|
324
|
+
@xml_content = ensure_xml_content(content)
|
325
|
+
end
|
326
|
+
|
327
|
+
def xhtml=(content)
|
328
|
+
self.xml_content = content
|
329
|
+
end
|
330
|
+
|
331
|
+
private
|
332
|
+
def set_xhtml_uri_as_default_uri(children)
|
333
|
+
children.collect do |child|
|
334
|
+
if child.is_a?(RSS::XML::Element) and
|
335
|
+
child.prefix.nil? and child.uri.nil?
|
336
|
+
RSS::XML::Element.new(child.name, nil, ::RSS::Atom::XHTML_URI,
|
337
|
+
child.attributes.dup,
|
338
|
+
set_xhtml_uri_as_default_uri(child.children))
|
339
|
+
else
|
340
|
+
child
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def self.append_features(klass)
|
347
|
+
super
|
348
|
+
|
349
|
+
klass.class_eval do
|
350
|
+
include EnsureXMLContent
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
module SetupDefaultDate
|
356
|
+
private
|
357
|
+
def _set_default_values
|
358
|
+
keep = {
|
359
|
+
:date => date,
|
360
|
+
:dc_dates => dc_dates.to_a.dup,
|
361
|
+
}
|
362
|
+
_date = _parse_date_if_needed(date)
|
363
|
+
if _date and !dc_dates.any? {|dc_date| dc_date.value == _date}
|
364
|
+
dc_date = self.class::DublinCoreDates::DublinCoreDate.new(self)
|
365
|
+
dc_date.value = _date.dup
|
366
|
+
dc_dates.unshift(dc_date)
|
367
|
+
end
|
368
|
+
self.date ||= self.dc_date
|
369
|
+
super
|
370
|
+
ensure
|
371
|
+
self.date = keep[:date]
|
372
|
+
dc_dates.replace(keep[:dc_dates])
|
373
|
+
end
|
374
|
+
|
375
|
+
def _parse_date_if_needed(date_value)
|
376
|
+
date_value = Time.parse(date_value) if date_value.is_a?(String)
|
377
|
+
date_value
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
module SetupDefaultLanguage
|
382
|
+
private
|
383
|
+
def _set_default_values
|
384
|
+
keep = {
|
385
|
+
:dc_languages => dc_languages.to_a.dup,
|
386
|
+
}
|
387
|
+
_language = language
|
388
|
+
if _language and
|
389
|
+
!dc_languages.any? {|dc_language| dc_language.value == _language}
|
390
|
+
dc_language = self.class::DublinCoreLanguages::DublinCoreLanguage.new(self)
|
391
|
+
dc_language.value = _language.dup
|
392
|
+
dc_languages.unshift(dc_language)
|
393
|
+
end
|
394
|
+
super
|
395
|
+
ensure
|
396
|
+
dc_languages.replace(keep[:dc_languages])
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
class RSSBase < Base
|
401
|
+
class << self
|
402
|
+
def make(*args, &block)
|
403
|
+
new(*args).make(&block)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
%w(xml_stylesheets channel image items textinput).each do |element|
|
408
|
+
attr_reader element
|
409
|
+
add_need_initialize_variable(element) do |object|
|
410
|
+
object.send("make_#{element}")
|
411
|
+
end
|
412
|
+
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
413
|
+
private
|
414
|
+
def setup_#{element}(feed)
|
415
|
+
@#{element}.to_feed(feed)
|
416
|
+
end
|
417
|
+
|
418
|
+
def make_#{element}
|
419
|
+
self.class::#{Utils.to_class_name(element)}.new(self)
|
420
|
+
end
|
421
|
+
EOC
|
422
|
+
end
|
423
|
+
|
424
|
+
attr_reader :feed_version
|
425
|
+
alias_method(:rss_version, :feed_version)
|
426
|
+
attr_accessor :version, :encoding, :standalone
|
427
|
+
|
428
|
+
def initialize(feed_version)
|
429
|
+
super(self)
|
430
|
+
@feed_type = nil
|
431
|
+
@feed_subtype = nil
|
432
|
+
@feed_version = feed_version
|
433
|
+
@version = "1.0"
|
434
|
+
@encoding = "UTF-8"
|
435
|
+
@standalone = nil
|
436
|
+
end
|
437
|
+
|
438
|
+
def make
|
439
|
+
yield(self)
|
440
|
+
to_feed
|
441
|
+
end
|
442
|
+
|
443
|
+
def to_feed
|
444
|
+
feed = make_feed
|
445
|
+
setup_xml_stylesheets(feed)
|
446
|
+
setup_elements(feed)
|
447
|
+
setup_other_elements(feed)
|
448
|
+
feed.validate
|
449
|
+
feed
|
450
|
+
end
|
451
|
+
|
452
|
+
private
|
453
|
+
remove_method :make_xml_stylesheets
|
454
|
+
def make_xml_stylesheets
|
455
|
+
XMLStyleSheets.new(self)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
class XMLStyleSheets < Base
|
460
|
+
def_array_element("xml_stylesheet", nil, "XMLStyleSheet")
|
461
|
+
|
462
|
+
class XMLStyleSheet < Base
|
463
|
+
|
464
|
+
::RSS::XMLStyleSheet::ATTRIBUTES.each do |attribute|
|
465
|
+
attr_accessor attribute
|
466
|
+
add_need_initialize_variable(attribute)
|
467
|
+
end
|
468
|
+
|
469
|
+
def to_feed(feed)
|
470
|
+
xss = ::RSS::XMLStyleSheet.new
|
471
|
+
guess_type_if_need(xss)
|
472
|
+
set = setup_values(xss)
|
473
|
+
if set
|
474
|
+
feed.xml_stylesheets << xss
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
private
|
479
|
+
def guess_type_if_need(xss)
|
480
|
+
if @type.nil?
|
481
|
+
xss.href = @href
|
482
|
+
@type = xss.type
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
def required_variable_names
|
487
|
+
%w(href type)
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
class ChannelBase < Base
|
493
|
+
include SetupDefaultDate
|
494
|
+
|
495
|
+
%w(cloud categories skipDays skipHours).each do |name|
|
496
|
+
def_classed_element(name)
|
497
|
+
end
|
498
|
+
|
499
|
+
%w(generator copyright description title).each do |name|
|
500
|
+
def_classed_element(name, nil, "content")
|
501
|
+
end
|
502
|
+
|
503
|
+
[
|
504
|
+
["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
|
505
|
+
["author", "name"],
|
506
|
+
["contributor", "name"],
|
507
|
+
].each do |name, attribute, additional_setup_maker|
|
508
|
+
def_classed_elements(name, attribute, &additional_setup_maker)
|
509
|
+
end
|
510
|
+
|
511
|
+
%w(id about language
|
512
|
+
managingEditor webMaster rating docs ttl).each do |element|
|
513
|
+
attr_accessor element
|
514
|
+
add_need_initialize_variable(element)
|
515
|
+
end
|
516
|
+
|
517
|
+
%w(date lastBuildDate).each do |date_element|
|
518
|
+
attr_reader date_element
|
519
|
+
add_need_initialize_variable(date_element)
|
520
|
+
end
|
521
|
+
|
522
|
+
def date=(_date)
|
523
|
+
@date = _parse_date_if_needed(_date)
|
524
|
+
end
|
525
|
+
|
526
|
+
def lastBuildDate=(_date)
|
527
|
+
@lastBuildDate = _parse_date_if_needed(_date)
|
528
|
+
end
|
529
|
+
|
530
|
+
def pubDate
|
531
|
+
date
|
532
|
+
end
|
533
|
+
|
534
|
+
def pubDate=(date)
|
535
|
+
self.date = date
|
536
|
+
end
|
537
|
+
|
538
|
+
def updated
|
539
|
+
date
|
540
|
+
end
|
541
|
+
|
542
|
+
def updated=(date)
|
543
|
+
self.date = date
|
544
|
+
end
|
545
|
+
|
546
|
+
alias_method(:rights, :copyright)
|
547
|
+
alias_method(:rights=, :copyright=)
|
548
|
+
|
549
|
+
alias_method(:subtitle, :description)
|
550
|
+
alias_method(:subtitle=, :description=)
|
551
|
+
|
552
|
+
def icon
|
553
|
+
image_favicon.about
|
554
|
+
end
|
555
|
+
|
556
|
+
def icon=(url)
|
557
|
+
image_favicon.about = url
|
558
|
+
end
|
559
|
+
|
560
|
+
def logo
|
561
|
+
maker.image.url
|
562
|
+
end
|
563
|
+
|
564
|
+
def logo=(url)
|
565
|
+
maker.image.url = url
|
566
|
+
end
|
567
|
+
|
568
|
+
class SkipDaysBase < Base
|
569
|
+
def_array_element("day")
|
570
|
+
|
571
|
+
class DayBase < Base
|
572
|
+
%w(content).each do |element|
|
573
|
+
attr_accessor element
|
574
|
+
add_need_initialize_variable(element)
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
class SkipHoursBase < Base
|
580
|
+
def_array_element("hour")
|
581
|
+
|
582
|
+
class HourBase < Base
|
583
|
+
%w(content).each do |element|
|
584
|
+
attr_accessor element
|
585
|
+
add_need_initialize_variable(element)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
class CloudBase < Base
|
591
|
+
%w(domain port path registerProcedure protocol).each do |element|
|
592
|
+
attr_accessor element
|
593
|
+
add_need_initialize_variable(element)
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
class CategoriesBase < Base
|
598
|
+
def_array_element("category", "categories")
|
599
|
+
|
600
|
+
class CategoryBase < Base
|
601
|
+
%w(domain content label).each do |element|
|
602
|
+
attr_accessor element
|
603
|
+
add_need_initialize_variable(element)
|
604
|
+
end
|
605
|
+
|
606
|
+
alias_method(:term, :domain)
|
607
|
+
alias_method(:term=, :domain=)
|
608
|
+
alias_method(:scheme, :content)
|
609
|
+
alias_method(:scheme=, :content=)
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
class LinksBase < Base
|
614
|
+
def_array_element("link")
|
615
|
+
|
616
|
+
class LinkBase < Base
|
617
|
+
%w(href rel type hreflang title length).each do |element|
|
618
|
+
attr_accessor element
|
619
|
+
add_need_initialize_variable(element)
|
620
|
+
end
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
class AuthorsBase < Base
|
625
|
+
def_array_element("author")
|
626
|
+
|
627
|
+
class AuthorBase < Base
|
628
|
+
include AtomPersonConstructBase
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
class ContributorsBase < Base
|
633
|
+
def_array_element("contributor")
|
634
|
+
|
635
|
+
class ContributorBase < Base
|
636
|
+
include AtomPersonConstructBase
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
class GeneratorBase < Base
|
641
|
+
%w(uri version content).each do |element|
|
642
|
+
attr_accessor element
|
643
|
+
add_need_initialize_variable(element)
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
class CopyrightBase < Base
|
648
|
+
include AtomTextConstructBase
|
649
|
+
end
|
650
|
+
|
651
|
+
class DescriptionBase < Base
|
652
|
+
include AtomTextConstructBase
|
653
|
+
end
|
654
|
+
|
655
|
+
class TitleBase < Base
|
656
|
+
include AtomTextConstructBase
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
class ImageBase < Base
|
661
|
+
%w(title url width height description).each do |element|
|
662
|
+
attr_accessor element
|
663
|
+
add_need_initialize_variable(element)
|
664
|
+
end
|
665
|
+
|
666
|
+
def link
|
667
|
+
@maker.channel.link
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
class ItemsBase < Base
|
672
|
+
def_array_element("item")
|
673
|
+
|
674
|
+
attr_accessor :do_sort, :max_size
|
675
|
+
|
676
|
+
def initialize(maker)
|
677
|
+
super
|
678
|
+
@do_sort = false
|
679
|
+
@max_size = -1
|
680
|
+
end
|
681
|
+
|
682
|
+
def normalize
|
683
|
+
if @max_size >= 0
|
684
|
+
sort_if_need[0...@max_size]
|
685
|
+
else
|
686
|
+
sort_if_need[0..@max_size]
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
private
|
691
|
+
def sort_if_need
|
692
|
+
if @do_sort.respond_to?(:call)
|
693
|
+
@items.sort do |x, y|
|
694
|
+
@do_sort.call(x, y)
|
695
|
+
end
|
696
|
+
elsif @do_sort
|
697
|
+
@items.sort do |x, y|
|
698
|
+
y <=> x
|
699
|
+
end
|
700
|
+
else
|
701
|
+
@items
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
class ItemBase < Base
|
706
|
+
include SetupDefaultDate
|
707
|
+
|
708
|
+
%w(guid enclosure source categories content).each do |name|
|
709
|
+
def_classed_element(name)
|
710
|
+
end
|
711
|
+
|
712
|
+
%w(rights description title).each do |name|
|
713
|
+
def_classed_element(name, nil, "content")
|
714
|
+
end
|
715
|
+
|
716
|
+
[
|
717
|
+
["author", "name"],
|
718
|
+
["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
|
719
|
+
["contributor", "name"],
|
720
|
+
].each do |name, attribute|
|
721
|
+
def_classed_elements(name, attribute)
|
722
|
+
end
|
723
|
+
|
724
|
+
%w(comments id published).each do |element|
|
725
|
+
attr_accessor element
|
726
|
+
add_need_initialize_variable(element)
|
727
|
+
end
|
728
|
+
|
729
|
+
%w(date).each do |date_element|
|
730
|
+
attr_reader date_element
|
731
|
+
add_need_initialize_variable(date_element)
|
732
|
+
end
|
733
|
+
|
734
|
+
def date=(_date)
|
735
|
+
@date = _parse_date_if_needed(_date)
|
736
|
+
end
|
737
|
+
|
738
|
+
def pubDate
|
739
|
+
date
|
740
|
+
end
|
741
|
+
|
742
|
+
def pubDate=(date)
|
743
|
+
self.date = date
|
744
|
+
end
|
745
|
+
|
746
|
+
def updated
|
747
|
+
date
|
748
|
+
end
|
749
|
+
|
750
|
+
def updated=(date)
|
751
|
+
self.date = date
|
752
|
+
end
|
753
|
+
|
754
|
+
alias_method(:summary, :description)
|
755
|
+
alias_method(:summary=, :description=)
|
756
|
+
|
757
|
+
def <=>(other)
|
758
|
+
_date = date || dc_date
|
759
|
+
_other_date = other.date || other.dc_date
|
760
|
+
if _date and _other_date
|
761
|
+
_date <=> _other_date
|
762
|
+
elsif _date
|
763
|
+
1
|
764
|
+
elsif _other_date
|
765
|
+
-1
|
766
|
+
else
|
767
|
+
0
|
768
|
+
end
|
769
|
+
end
|
770
|
+
|
771
|
+
class GuidBase < Base
|
772
|
+
%w(isPermaLink content).each do |element|
|
773
|
+
attr_accessor element
|
774
|
+
add_need_initialize_variable(element)
|
775
|
+
end
|
776
|
+
|
777
|
+
def permanent_link?
|
778
|
+
isPermaLink
|
779
|
+
end
|
780
|
+
|
781
|
+
def permanent_link=(bool)
|
782
|
+
self.isPermaLink = bool
|
783
|
+
end
|
784
|
+
end
|
785
|
+
|
786
|
+
class EnclosureBase < Base
|
787
|
+
%w(url length type).each do |element|
|
788
|
+
attr_accessor element
|
789
|
+
add_need_initialize_variable(element)
|
790
|
+
end
|
791
|
+
end
|
792
|
+
|
793
|
+
class SourceBase < Base
|
794
|
+
include SetupDefaultDate
|
795
|
+
|
796
|
+
%w(authors categories contributors generator icon
|
797
|
+
logo rights subtitle title).each do |name|
|
798
|
+
def_classed_element(name)
|
799
|
+
end
|
800
|
+
|
801
|
+
[
|
802
|
+
["link", "href"],
|
803
|
+
].each do |name, attribute|
|
804
|
+
def_classed_elements(name, attribute)
|
805
|
+
end
|
806
|
+
|
807
|
+
%w(id content).each do |element|
|
808
|
+
attr_accessor element
|
809
|
+
add_need_initialize_variable(element)
|
810
|
+
end
|
811
|
+
|
812
|
+
alias_method(:url, :link)
|
813
|
+
alias_method(:url=, :link=)
|
814
|
+
|
815
|
+
%w(date).each do |date_element|
|
816
|
+
attr_reader date_element
|
817
|
+
add_need_initialize_variable(date_element)
|
818
|
+
end
|
819
|
+
|
820
|
+
def date=(_date)
|
821
|
+
@date = _parse_date_if_needed(_date)
|
822
|
+
end
|
823
|
+
|
824
|
+
def updated
|
825
|
+
date
|
826
|
+
end
|
827
|
+
|
828
|
+
def updated=(date)
|
829
|
+
self.date = date
|
830
|
+
end
|
831
|
+
|
832
|
+
private
|
833
|
+
AuthorsBase = ChannelBase::AuthorsBase
|
834
|
+
CategoriesBase = ChannelBase::CategoriesBase
|
835
|
+
ContributorsBase = ChannelBase::ContributorsBase
|
836
|
+
GeneratorBase = ChannelBase::GeneratorBase
|
837
|
+
|
838
|
+
class IconBase < Base
|
839
|
+
%w(url).each do |element|
|
840
|
+
attr_accessor element
|
841
|
+
add_need_initialize_variable(element)
|
842
|
+
end
|
843
|
+
end
|
844
|
+
|
845
|
+
LinksBase = ChannelBase::LinksBase
|
846
|
+
|
847
|
+
class LogoBase < Base
|
848
|
+
%w(uri).each do |element|
|
849
|
+
attr_accessor element
|
850
|
+
add_need_initialize_variable(element)
|
851
|
+
end
|
852
|
+
end
|
853
|
+
|
854
|
+
class RightsBase < Base
|
855
|
+
include AtomTextConstructBase
|
856
|
+
end
|
857
|
+
|
858
|
+
class SubtitleBase < Base
|
859
|
+
include AtomTextConstructBase
|
860
|
+
end
|
861
|
+
|
862
|
+
class TitleBase < Base
|
863
|
+
include AtomTextConstructBase
|
864
|
+
end
|
865
|
+
end
|
866
|
+
|
867
|
+
CategoriesBase = ChannelBase::CategoriesBase
|
868
|
+
AuthorsBase = ChannelBase::AuthorsBase
|
869
|
+
LinksBase = ChannelBase::LinksBase
|
870
|
+
ContributorsBase = ChannelBase::ContributorsBase
|
871
|
+
|
872
|
+
class RightsBase < Base
|
873
|
+
include AtomTextConstructBase
|
874
|
+
end
|
875
|
+
|
876
|
+
class DescriptionBase < Base
|
877
|
+
include AtomTextConstructBase
|
878
|
+
end
|
879
|
+
|
880
|
+
class ContentBase < Base
|
881
|
+
include AtomTextConstructBase::EnsureXMLContent
|
882
|
+
|
883
|
+
%w(src).each do |element|
|
884
|
+
attr_accessor(element)
|
885
|
+
add_need_initialize_variable(element)
|
886
|
+
end
|
887
|
+
|
888
|
+
def xml_content=(content)
|
889
|
+
content = ensure_xml_content(content) if inline_xhtml?
|
890
|
+
@xml_content = content
|
891
|
+
end
|
892
|
+
|
893
|
+
alias_method(:xml, :xml_content)
|
894
|
+
alias_method(:xml=, :xml_content=)
|
895
|
+
|
896
|
+
def inline_text?
|
897
|
+
[nil, "text", "html"].include?(@type)
|
898
|
+
end
|
899
|
+
|
900
|
+
def inline_html?
|
901
|
+
@type == "html"
|
902
|
+
end
|
903
|
+
|
904
|
+
def inline_xhtml?
|
905
|
+
@type == "xhtml"
|
906
|
+
end
|
907
|
+
|
908
|
+
def inline_other?
|
909
|
+
!out_of_line? and ![nil, "text", "html", "xhtml"].include?(@type)
|
910
|
+
end
|
911
|
+
|
912
|
+
def inline_other_text?
|
913
|
+
return false if @type.nil? or out_of_line?
|
914
|
+
/\Atext\//i.match(@type) ? true : false
|
915
|
+
end
|
916
|
+
|
917
|
+
def inline_other_xml?
|
918
|
+
return false if @type.nil? or out_of_line?
|
919
|
+
/[\+\/]xml\z/i.match(@type) ? true : false
|
920
|
+
end
|
921
|
+
|
922
|
+
def inline_other_base64?
|
923
|
+
return false if @type.nil? or out_of_line?
|
924
|
+
@type.include?("/") and !inline_other_text? and !inline_other_xml?
|
925
|
+
end
|
926
|
+
|
927
|
+
def out_of_line?
|
928
|
+
not @src.nil? and @content.nil?
|
929
|
+
end
|
930
|
+
end
|
931
|
+
|
932
|
+
class TitleBase < Base
|
933
|
+
include AtomTextConstructBase
|
934
|
+
end
|
935
|
+
end
|
936
|
+
end
|
937
|
+
|
938
|
+
class TextinputBase < Base
|
939
|
+
%w(title description name link).each do |element|
|
940
|
+
attr_accessor element
|
941
|
+
add_need_initialize_variable(element)
|
942
|
+
end
|
943
|
+
end
|
944
|
+
end
|
945
|
+
end
|