rss 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +88 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/lib/rss.rb +92 -0
  11. data/lib/rss/0.9.rb +462 -0
  12. data/lib/rss/1.0.rb +485 -0
  13. data/lib/rss/2.0.rb +143 -0
  14. data/lib/rss/atom.rb +1025 -0
  15. data/lib/rss/content.rb +34 -0
  16. data/lib/rss/content/1.0.rb +10 -0
  17. data/lib/rss/content/2.0.rb +12 -0
  18. data/lib/rss/converter.rb +171 -0
  19. data/lib/rss/dublincore.rb +164 -0
  20. data/lib/rss/dublincore/1.0.rb +13 -0
  21. data/lib/rss/dublincore/2.0.rb +13 -0
  22. data/lib/rss/dublincore/atom.rb +17 -0
  23. data/lib/rss/image.rb +198 -0
  24. data/lib/rss/itunes.rb +413 -0
  25. data/lib/rss/maker.rb +79 -0
  26. data/lib/rss/maker/0.9.rb +509 -0
  27. data/lib/rss/maker/1.0.rb +436 -0
  28. data/lib/rss/maker/2.0.rb +224 -0
  29. data/lib/rss/maker/atom.rb +173 -0
  30. data/lib/rss/maker/base.rb +945 -0
  31. data/lib/rss/maker/content.rb +22 -0
  32. data/lib/rss/maker/dublincore.rb +122 -0
  33. data/lib/rss/maker/entry.rb +164 -0
  34. data/lib/rss/maker/feed.rb +427 -0
  35. data/lib/rss/maker/image.rb +112 -0
  36. data/lib/rss/maker/itunes.rb +243 -0
  37. data/lib/rss/maker/slash.rb +34 -0
  38. data/lib/rss/maker/syndication.rb +19 -0
  39. data/lib/rss/maker/taxonomy.rb +119 -0
  40. data/lib/rss/maker/trackback.rb +62 -0
  41. data/lib/rss/parser.rb +589 -0
  42. data/lib/rss/rexmlparser.rb +50 -0
  43. data/lib/rss/rss.rb +1346 -0
  44. data/lib/rss/slash.rb +52 -0
  45. data/lib/rss/syndication.rb +69 -0
  46. data/lib/rss/taxonomy.rb +148 -0
  47. data/lib/rss/trackback.rb +291 -0
  48. data/lib/rss/utils.rb +200 -0
  49. data/lib/rss/xml-stylesheet.rb +106 -0
  50. data/lib/rss/xml.rb +72 -0
  51. data/lib/rss/xmlparser.rb +95 -0
  52. data/lib/rss/xmlscanner.rb +122 -0
  53. data/rss.gemspec +38 -0
  54. metadata +138 -0
@@ -0,0 +1,485 @@
1
+ # frozen_string_literal: false
2
+ require_relative "parser"
3
+
4
+ module RSS
5
+
6
+ ##
7
+ # = RSS 1.0 support
8
+ #
9
+ # RSS has three different versions. This module contains support for version
10
+ # 1.0[http://web.resource.org/rss/1.0/]
11
+ #
12
+ # == Producing RSS 1.0
13
+ #
14
+ # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
15
+ #
16
+ # require "rss"
17
+ #
18
+ # rss = RSS::Maker.make("1.0") do |maker|
19
+ # maker.channel.language = "en"
20
+ # maker.channel.author = "matz"
21
+ # maker.channel.about = "About my feed."
22
+ # maker.channel.updated = Time.now.to_s
23
+ # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
24
+ # maker.channel.title = "Example Feed"
25
+ # maker.channel.description = "A longer description of my feed."
26
+ # maker.items.new_item do |item|
27
+ # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
28
+ # item.title = "Ruby 1.9.2-p136 is released"
29
+ # item.updated = Time.now.to_s
30
+ # end
31
+ # end
32
+ #
33
+ # puts rss
34
+ #
35
+ # As you can see, this is a very Builder-like DSL. This code will spit out an
36
+ # RSS 1.0 feed with one item. If we needed a second item, we'd make another
37
+ # block with maker.items.new_item and build a second one.
38
+ module RSS10
39
+ NSPOOL = {}
40
+ ELEMENTS = []
41
+
42
+ def self.append_features(klass)
43
+ super
44
+
45
+ klass.install_must_call_validator('', ::RSS::URI)
46
+ end
47
+
48
+ end
49
+
50
+ class RDF < Element
51
+
52
+ include RSS10
53
+ include RootElementMixin
54
+
55
+ class << self
56
+
57
+ def required_uri
58
+ URI
59
+ end
60
+
61
+ end
62
+
63
+ @tag_name = 'RDF'
64
+
65
+ PREFIX = 'rdf'
66
+ URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
67
+
68
+ install_ns('', ::RSS::URI)
69
+ install_ns(PREFIX, URI)
70
+
71
+ [
72
+ ["channel", nil],
73
+ ["image", "?"],
74
+ ["item", "+", :children],
75
+ ["textinput", "?"],
76
+ ].each do |tag, occurs, type|
77
+ type ||= :child
78
+ __send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
79
+ end
80
+
81
+ alias_method(:rss_version, :feed_version)
82
+ def initialize(version=nil, encoding=nil, standalone=nil)
83
+ super('1.0', version, encoding, standalone)
84
+ @feed_type = "rss"
85
+ end
86
+
87
+ def full_name
88
+ tag_name_with_prefix(PREFIX)
89
+ end
90
+
91
+ class Li < Element
92
+
93
+ include RSS10
94
+
95
+ class << self
96
+ def required_uri
97
+ URI
98
+ end
99
+ end
100
+
101
+ [
102
+ ["resource", [URI, ""], true]
103
+ ].each do |name, uri, required|
104
+ install_get_attribute(name, uri, required)
105
+ end
106
+
107
+ def initialize(*args)
108
+ if Utils.element_initialize_arguments?(args)
109
+ super
110
+ else
111
+ super()
112
+ self.resource = args[0]
113
+ end
114
+ end
115
+
116
+ def full_name
117
+ tag_name_with_prefix(PREFIX)
118
+ end
119
+ end
120
+
121
+ class Seq < Element
122
+
123
+ include RSS10
124
+
125
+ Li = ::RSS::RDF::Li
126
+
127
+ class << self
128
+ def required_uri
129
+ URI
130
+ end
131
+ end
132
+
133
+ @tag_name = 'Seq'
134
+
135
+ install_have_children_element("li", URI, "*")
136
+ install_must_call_validator('rdf', ::RSS::RDF::URI)
137
+
138
+ def initialize(*args)
139
+ if Utils.element_initialize_arguments?(args)
140
+ super
141
+ else
142
+ super()
143
+ @li = args[0] if args[0]
144
+ end
145
+ end
146
+
147
+ def full_name
148
+ tag_name_with_prefix(PREFIX)
149
+ end
150
+
151
+ def setup_maker(target)
152
+ lis.each do |li|
153
+ target << li.resource
154
+ end
155
+ end
156
+ end
157
+
158
+ class Bag < Element
159
+
160
+ include RSS10
161
+
162
+ Li = ::RSS::RDF::Li
163
+
164
+ class << self
165
+ def required_uri
166
+ URI
167
+ end
168
+ end
169
+
170
+ @tag_name = 'Bag'
171
+
172
+ install_have_children_element("li", URI, "*")
173
+ install_must_call_validator('rdf', URI)
174
+
175
+ def initialize(*args)
176
+ if Utils.element_initialize_arguments?(args)
177
+ super
178
+ else
179
+ super()
180
+ @li = args[0] if args[0]
181
+ end
182
+ end
183
+
184
+ def full_name
185
+ tag_name_with_prefix(PREFIX)
186
+ end
187
+
188
+ def setup_maker(target)
189
+ lis.each do |li|
190
+ target << li.resource
191
+ end
192
+ end
193
+ end
194
+
195
+ class Channel < Element
196
+
197
+ include RSS10
198
+
199
+ class << self
200
+
201
+ def required_uri
202
+ ::RSS::URI
203
+ end
204
+
205
+ end
206
+
207
+ [
208
+ ["about", URI, true]
209
+ ].each do |name, uri, required|
210
+ install_get_attribute(name, uri, required, nil, nil,
211
+ "#{PREFIX}:#{name}")
212
+ end
213
+
214
+ [
215
+ ['title', nil, :text],
216
+ ['link', nil, :text],
217
+ ['description', nil, :text],
218
+ ['image', '?', :have_child],
219
+ ['items', nil, :have_child],
220
+ ['textinput', '?', :have_child],
221
+ ].each do |tag, occurs, type|
222
+ __send__("install_#{type}_element", tag, ::RSS::URI, occurs)
223
+ end
224
+
225
+ def initialize(*args)
226
+ if Utils.element_initialize_arguments?(args)
227
+ super
228
+ else
229
+ super()
230
+ self.about = args[0]
231
+ end
232
+ end
233
+
234
+ private
235
+ def maker_target(maker)
236
+ maker.channel
237
+ end
238
+
239
+ def setup_maker_attributes(channel)
240
+ channel.about = about
241
+ end
242
+
243
+ class Image < Element
244
+
245
+ include RSS10
246
+
247
+ class << self
248
+
249
+ def required_uri
250
+ ::RSS::URI
251
+ end
252
+
253
+ end
254
+
255
+ [
256
+ ["resource", URI, true]
257
+ ].each do |name, uri, required|
258
+ install_get_attribute(name, uri, required, nil, nil,
259
+ "#{PREFIX}:#{name}")
260
+ end
261
+
262
+ def initialize(*args)
263
+ if Utils.element_initialize_arguments?(args)
264
+ super
265
+ else
266
+ super()
267
+ self.resource = args[0]
268
+ end
269
+ end
270
+ end
271
+
272
+ class Textinput < Element
273
+
274
+ include RSS10
275
+
276
+ class << self
277
+
278
+ def required_uri
279
+ ::RSS::URI
280
+ end
281
+
282
+ end
283
+
284
+ [
285
+ ["resource", URI, true]
286
+ ].each do |name, uri, required|
287
+ install_get_attribute(name, uri, required, nil, nil,
288
+ "#{PREFIX}:#{name}")
289
+ end
290
+
291
+ def initialize(*args)
292
+ if Utils.element_initialize_arguments?(args)
293
+ super
294
+ else
295
+ super()
296
+ self.resource = args[0]
297
+ end
298
+ end
299
+ end
300
+
301
+ class Items < Element
302
+
303
+ include RSS10
304
+
305
+ Seq = ::RSS::RDF::Seq
306
+
307
+ class << self
308
+
309
+ def required_uri
310
+ ::RSS::URI
311
+ end
312
+
313
+ end
314
+
315
+ install_have_child_element("Seq", URI, nil)
316
+ install_must_call_validator('rdf', URI)
317
+
318
+ def initialize(*args)
319
+ if Utils.element_initialize_arguments?(args)
320
+ super
321
+ else
322
+ super()
323
+ self.Seq = args[0]
324
+ end
325
+ self.Seq ||= Seq.new
326
+ end
327
+
328
+ def resources
329
+ if @Seq
330
+ @Seq.lis.collect do |li|
331
+ li.resource
332
+ end
333
+ else
334
+ []
335
+ end
336
+ end
337
+ end
338
+ end
339
+
340
+ class Image < Element
341
+
342
+ include RSS10
343
+
344
+ class << self
345
+
346
+ def required_uri
347
+ ::RSS::URI
348
+ end
349
+
350
+ end
351
+
352
+ [
353
+ ["about", URI, true]
354
+ ].each do |name, uri, required|
355
+ install_get_attribute(name, uri, required, nil, nil,
356
+ "#{PREFIX}:#{name}")
357
+ end
358
+
359
+ %w(title url link).each do |name|
360
+ install_text_element(name, ::RSS::URI, nil)
361
+ end
362
+
363
+ def initialize(*args)
364
+ if Utils.element_initialize_arguments?(args)
365
+ super
366
+ else
367
+ super()
368
+ self.about = args[0]
369
+ end
370
+ end
371
+
372
+ private
373
+ def maker_target(maker)
374
+ maker.image
375
+ end
376
+ end
377
+
378
+ class Item < Element
379
+
380
+ include RSS10
381
+
382
+ class << self
383
+
384
+ def required_uri
385
+ ::RSS::URI
386
+ end
387
+
388
+ end
389
+
390
+
391
+ [
392
+ ["about", URI, true]
393
+ ].each do |name, uri, required|
394
+ install_get_attribute(name, uri, required, nil, nil,
395
+ "#{PREFIX}:#{name}")
396
+ end
397
+
398
+ [
399
+ ["title", nil],
400
+ ["link", nil],
401
+ ["description", "?"],
402
+ ].each do |tag, occurs|
403
+ install_text_element(tag, ::RSS::URI, occurs)
404
+ end
405
+
406
+ def initialize(*args)
407
+ if Utils.element_initialize_arguments?(args)
408
+ super
409
+ else
410
+ super()
411
+ self.about = args[0]
412
+ end
413
+ end
414
+
415
+ private
416
+ def maker_target(items)
417
+ if items.respond_to?("items")
418
+ # For backward compatibility
419
+ items = items.items
420
+ end
421
+ items.new_item
422
+ end
423
+ end
424
+
425
+ class Textinput < Element
426
+
427
+ include RSS10
428
+
429
+ class << self
430
+
431
+ def required_uri
432
+ ::RSS::URI
433
+ end
434
+
435
+ end
436
+
437
+ [
438
+ ["about", URI, true]
439
+ ].each do |name, uri, required|
440
+ install_get_attribute(name, uri, required, nil, nil,
441
+ "#{PREFIX}:#{name}")
442
+ end
443
+
444
+ %w(title description name link).each do |name|
445
+ install_text_element(name, ::RSS::URI, nil)
446
+ end
447
+
448
+ def initialize(*args)
449
+ if Utils.element_initialize_arguments?(args)
450
+ super
451
+ else
452
+ super()
453
+ self.about = args[0]
454
+ end
455
+ end
456
+
457
+ private
458
+ def maker_target(maker)
459
+ maker.textinput
460
+ end
461
+ end
462
+
463
+ end
464
+
465
+ RSS10::ELEMENTS.each do |name|
466
+ BaseListener.install_get_text_element(URI, name, name)
467
+ end
468
+
469
+ module ListenerMixin
470
+ private
471
+ def initial_start_RDF(tag_name, prefix, attrs, ns)
472
+ check_ns(tag_name, prefix, ns, RDF::URI, false)
473
+
474
+ @rss = RDF.new(@version, @encoding, @standalone)
475
+ @rss.do_validate = @do_validate
476
+ @rss.xml_stylesheets = @xml_stylesheets
477
+ @last_element = @rss
478
+ pr = Proc.new do |text, tags|
479
+ @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
480
+ end
481
+ @proc_stack.push(pr)
482
+ end
483
+ end
484
+
485
+ end