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,52 @@
1
+ # frozen_string_literal: false
2
+ require 'rss/1.0'
3
+
4
+ module RSS
5
+ # The prefix for the Slash XML namespace.
6
+ SLASH_PREFIX = 'slash'
7
+ # The URI of the Slash specification.
8
+ SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"
9
+
10
+ RDF.install_ns(SLASH_PREFIX, SLASH_URI)
11
+
12
+ module SlashModel
13
+ extend BaseModel
14
+
15
+ ELEMENT_INFOS = \
16
+ [
17
+ ["section"],
18
+ ["department"],
19
+ ["comments", :positive_integer],
20
+ ["hit_parade", :csv_integer],
21
+ ]
22
+
23
+ class << self
24
+ def append_features(klass)
25
+ super
26
+
27
+ return if klass.instance_of?(Module)
28
+ klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI)
29
+ ELEMENT_INFOS.each do |name, type, *additional_infos|
30
+ full_name = "#{SLASH_PREFIX}_#{name}"
31
+ klass.install_text_element(full_name, SLASH_URI, "?",
32
+ full_name, type, name)
33
+ end
34
+
35
+ klass.module_eval do
36
+ alias_method(:slash_hit_parades, :slash_hit_parade)
37
+ undef_method(:slash_hit_parade)
38
+ alias_method(:slash_hit_parade, :slash_hit_parade_content)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ class RDF
45
+ class Item; include SlashModel; end
46
+ end
47
+
48
+ SlashModel::ELEMENT_INFOS.each do |name, type|
49
+ accessor_base = "#{SLASH_PREFIX}_#{name}"
50
+ BaseListener.install_get_text_element(SLASH_URI, name, accessor_base)
51
+ end
52
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: false
2
+ require "rss/1.0"
3
+
4
+ module RSS
5
+ # The prefix for the Syndication XML namespace.
6
+ SY_PREFIX = 'sy'
7
+ # The URI of the Syndication specification.
8
+ SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
9
+
10
+ RDF.install_ns(SY_PREFIX, SY_URI)
11
+
12
+ module SyndicationModel
13
+
14
+ extend BaseModel
15
+
16
+ ELEMENTS = []
17
+
18
+ def self.append_features(klass)
19
+ super
20
+
21
+ klass.install_must_call_validator(SY_PREFIX, SY_URI)
22
+ klass.module_eval do
23
+ [
24
+ ["updatePeriod"],
25
+ ["updateFrequency", :positive_integer]
26
+ ].each do |name, type|
27
+ install_text_element(name, SY_URI, "?",
28
+ "#{SY_PREFIX}_#{name}", type,
29
+ "#{SY_PREFIX}:#{name}")
30
+ end
31
+
32
+ %w(updateBase).each do |name|
33
+ install_date_element(name, SY_URI, "?",
34
+ "#{SY_PREFIX}_#{name}", 'w3cdtf',
35
+ "#{SY_PREFIX}:#{name}")
36
+ end
37
+ end
38
+
39
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
40
+ alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
41
+ def sy_updatePeriod=(new_value)
42
+ new_value = new_value.strip
43
+ validate_sy_updatePeriod(new_value) if @do_validate
44
+ self._sy_updatePeriod = new_value
45
+ end
46
+ EOC
47
+ end
48
+
49
+ private
50
+ SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
51
+ def validate_sy_updatePeriod(value) # :nodoc:
52
+ unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
53
+ raise NotAvailableValueError.new("updatePeriod", value)
54
+ end
55
+ end
56
+ end
57
+
58
+ class RDF
59
+ class Channel; include SyndicationModel; end
60
+ end
61
+
62
+ prefix_size = SY_PREFIX.size + 1
63
+ SyndicationModel::ELEMENTS.uniq!
64
+ SyndicationModel::ELEMENTS.each do |full_name|
65
+ name = full_name[prefix_size..-1]
66
+ BaseListener.install_get_text_element(SY_URI, name, full_name)
67
+ end
68
+
69
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: false
2
+ require "rss/1.0"
3
+ require_relative "dublincore"
4
+
5
+ module RSS
6
+ # The prefix for the Taxonomy XML namespace.
7
+ TAXO_PREFIX = "taxo"
8
+ # The URI for the specification of the Taxonomy XML namespace.
9
+ TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
10
+
11
+ RDF.install_ns(TAXO_PREFIX, TAXO_URI)
12
+
13
+ # The listing of all the taxonomy elements, with the appropriate namespace.
14
+ TAXO_ELEMENTS = []
15
+
16
+ %w(link).each do |name|
17
+ full_name = "#{TAXO_PREFIX}_#{name}"
18
+ BaseListener.install_get_text_element(TAXO_URI, name, full_name)
19
+ TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
20
+ end
21
+
22
+ %w(topic topics).each do |name|
23
+ class_name = Utils.to_class_name(name)
24
+ BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
25
+ TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
26
+ end
27
+
28
+ module TaxonomyTopicsModel
29
+ extend BaseModel
30
+
31
+ def self.append_features(klass)
32
+ super
33
+
34
+ klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
35
+ %w(topics).each do |name|
36
+ klass.install_have_child_element(name, TAXO_URI, "?",
37
+ "#{TAXO_PREFIX}_#{name}")
38
+ end
39
+ end
40
+
41
+ class TaxonomyTopics < Element
42
+ include RSS10
43
+
44
+ Bag = ::RSS::RDF::Bag
45
+
46
+ class << self
47
+ def required_prefix
48
+ TAXO_PREFIX
49
+ end
50
+
51
+ def required_uri
52
+ TAXO_URI
53
+ end
54
+ end
55
+
56
+ @tag_name = "topics"
57
+
58
+ install_have_child_element("Bag", RDF::URI, nil)
59
+ install_must_call_validator('rdf', RDF::URI)
60
+
61
+ def initialize(*args)
62
+ if Utils.element_initialize_arguments?(args)
63
+ super
64
+ else
65
+ super()
66
+ self.Bag = args[0]
67
+ end
68
+ self.Bag ||= Bag.new
69
+ end
70
+
71
+ def full_name
72
+ tag_name_with_prefix(TAXO_PREFIX)
73
+ end
74
+
75
+ def maker_target(target)
76
+ target.taxo_topics
77
+ end
78
+
79
+ def resources
80
+ if @Bag
81
+ @Bag.lis.collect do |li|
82
+ li.resource
83
+ end
84
+ else
85
+ []
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ module TaxonomyTopicModel
92
+ extend BaseModel
93
+
94
+ def self.append_features(klass)
95
+ super
96
+ var_name = "#{TAXO_PREFIX}_topic"
97
+ klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
98
+ end
99
+
100
+ class TaxonomyTopic < Element
101
+ include RSS10
102
+
103
+ include DublinCoreModel
104
+ include TaxonomyTopicsModel
105
+
106
+ class << self
107
+ def required_prefix
108
+ TAXO_PREFIX
109
+ end
110
+
111
+ def required_uri
112
+ TAXO_URI
113
+ end
114
+ end
115
+
116
+ @tag_name = "topic"
117
+
118
+ install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
119
+ "#{RDF::PREFIX}:about")
120
+ install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
121
+
122
+ def initialize(*args)
123
+ if Utils.element_initialize_arguments?(args)
124
+ super
125
+ else
126
+ super()
127
+ self.about = args[0]
128
+ end
129
+ end
130
+
131
+ def full_name
132
+ tag_name_with_prefix(TAXO_PREFIX)
133
+ end
134
+
135
+ def maker_target(target)
136
+ target.new_taxo_topic
137
+ end
138
+ end
139
+ end
140
+
141
+ class RDF
142
+ include TaxonomyTopicModel
143
+ class Channel
144
+ include TaxonomyTopicsModel
145
+ end
146
+ class Item; include TaxonomyTopicsModel; end
147
+ end
148
+ end
@@ -0,0 +1,291 @@
1
+ # frozen_string_literal: false
2
+ # This file contains the implementation of trackbacks. It is entirely internal
3
+ # and not useful to outside developers.
4
+ require 'rss/1.0'
5
+ require 'rss/2.0'
6
+
7
+ module RSS # :nodoc: all
8
+
9
+ TRACKBACK_PREFIX = 'trackback'
10
+ TRACKBACK_URI = 'http://madskills.com/public/xml/rss/module/trackback/'
11
+
12
+ RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
13
+ Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
14
+
15
+ module TrackBackUtils
16
+ private
17
+ def trackback_validate(ignore_unknown_element, tags, uri)
18
+ return if tags.nil?
19
+ if tags.find {|tag| tag == "about"} and
20
+ !tags.find {|tag| tag == "ping"}
21
+ raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
22
+ end
23
+ end
24
+ end
25
+
26
+ module BaseTrackBackModel
27
+
28
+ ELEMENTS = %w(ping about)
29
+
30
+ def append_features(klass)
31
+ super
32
+
33
+ unless klass.class == Module
34
+ klass.module_eval {include TrackBackUtils}
35
+
36
+ klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
37
+ %w(ping).each do |name|
38
+ var_name = "#{TRACKBACK_PREFIX}_#{name}"
39
+ klass_name = "TrackBack#{Utils.to_class_name(name)}"
40
+ klass.install_have_child_element(name, TRACKBACK_URI, "?", var_name)
41
+ klass.module_eval(<<-EOC, __FILE__, __LINE__)
42
+ remove_method :#{var_name}
43
+ def #{var_name}
44
+ @#{var_name} and @#{var_name}.value
45
+ end
46
+
47
+ remove_method :#{var_name}=
48
+ def #{var_name}=(value)
49
+ @#{var_name} = Utils.new_with_value_if_need(#{klass_name}, value)
50
+ end
51
+ EOC
52
+ end
53
+
54
+ [%w(about s)].each do |name, postfix|
55
+ var_name = "#{TRACKBACK_PREFIX}_#{name}"
56
+ klass_name = "TrackBack#{Utils.to_class_name(name)}"
57
+ klass.install_have_children_element(name, TRACKBACK_URI, "*",
58
+ var_name)
59
+ klass.module_eval(<<-EOC, __FILE__, __LINE__)
60
+ remove_method :#{var_name}
61
+ def #{var_name}(*args)
62
+ if args.empty?
63
+ @#{var_name}.first and @#{var_name}.first.value
64
+ else
65
+ ret = @#{var_name}.__send__("[]", *args)
66
+ if ret.is_a?(Array)
67
+ ret.collect {|x| x.value}
68
+ else
69
+ ret.value
70
+ end
71
+ end
72
+ end
73
+
74
+ remove_method :#{var_name}=
75
+ remove_method :set_#{var_name}
76
+ def #{var_name}=(*args)
77
+ if args.size == 1
78
+ item = Utils.new_with_value_if_need(#{klass_name}, args[0])
79
+ @#{var_name}.push(item)
80
+ else
81
+ new_val = args.last
82
+ if new_val.is_a?(Array)
83
+ new_val = new_value.collect do |val|
84
+ Utils.new_with_value_if_need(#{klass_name}, val)
85
+ end
86
+ else
87
+ new_val = Utils.new_with_value_if_need(#{klass_name}, new_val)
88
+ end
89
+ @#{var_name}.__send__("[]=", *(args[0..-2] + [new_val]))
90
+ end
91
+ end
92
+ alias set_#{var_name} #{var_name}=
93
+ EOC
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ module TrackBackModel10
100
+ extend BaseModel
101
+ extend BaseTrackBackModel
102
+
103
+ class TrackBackPing < Element
104
+ include RSS10
105
+
106
+ class << self
107
+
108
+ def required_prefix
109
+ TRACKBACK_PREFIX
110
+ end
111
+
112
+ def required_uri
113
+ TRACKBACK_URI
114
+ end
115
+
116
+ end
117
+
118
+ @tag_name = "ping"
119
+
120
+ [
121
+ ["resource", ::RSS::RDF::URI, true]
122
+ ].each do |name, uri, required|
123
+ install_get_attribute(name, uri, required, nil, nil,
124
+ "#{::RSS::RDF::PREFIX}:#{name}")
125
+ end
126
+
127
+ alias_method(:value, :resource)
128
+ alias_method(:value=, :resource=)
129
+ def initialize(*args)
130
+ if Utils.element_initialize_arguments?(args)
131
+ super
132
+ else
133
+ super()
134
+ self.resource = args[0]
135
+ end
136
+ end
137
+
138
+ def full_name
139
+ tag_name_with_prefix(TRACKBACK_PREFIX)
140
+ end
141
+ end
142
+
143
+ class TrackBackAbout < Element
144
+ include RSS10
145
+
146
+ class << self
147
+
148
+ def required_prefix
149
+ TRACKBACK_PREFIX
150
+ end
151
+
152
+ def required_uri
153
+ TRACKBACK_URI
154
+ end
155
+
156
+ end
157
+
158
+ @tag_name = "about"
159
+
160
+ [
161
+ ["resource", ::RSS::RDF::URI, true]
162
+ ].each do |name, uri, required|
163
+ install_get_attribute(name, uri, required, nil, nil,
164
+ "#{::RSS::RDF::PREFIX}:#{name}")
165
+ end
166
+
167
+ alias_method(:value, :resource)
168
+ alias_method(:value=, :resource=)
169
+
170
+ def initialize(*args)
171
+ if Utils.element_initialize_arguments?(args)
172
+ super
173
+ else
174
+ super()
175
+ self.resource = args[0]
176
+ end
177
+ end
178
+
179
+ def full_name
180
+ tag_name_with_prefix(TRACKBACK_PREFIX)
181
+ end
182
+
183
+ private
184
+ def maker_target(abouts)
185
+ abouts.new_about
186
+ end
187
+
188
+ def setup_maker_attributes(about)
189
+ about.resource = self.resource
190
+ end
191
+
192
+ end
193
+ end
194
+
195
+ module TrackBackModel20
196
+ extend BaseModel
197
+ extend BaseTrackBackModel
198
+
199
+ class TrackBackPing < Element
200
+ include RSS09
201
+
202
+ @tag_name = "ping"
203
+
204
+ content_setup
205
+
206
+ class << self
207
+
208
+ def required_prefix
209
+ TRACKBACK_PREFIX
210
+ end
211
+
212
+ def required_uri
213
+ TRACKBACK_URI
214
+ end
215
+
216
+ end
217
+
218
+ alias_method(:value, :content)
219
+ alias_method(:value=, :content=)
220
+
221
+ def initialize(*args)
222
+ if Utils.element_initialize_arguments?(args)
223
+ super
224
+ else
225
+ super()
226
+ self.content = args[0]
227
+ end
228
+ end
229
+
230
+ def full_name
231
+ tag_name_with_prefix(TRACKBACK_PREFIX)
232
+ end
233
+
234
+ end
235
+
236
+ class TrackBackAbout < Element
237
+ include RSS09
238
+
239
+ @tag_name = "about"
240
+
241
+ content_setup
242
+
243
+ class << self
244
+
245
+ def required_prefix
246
+ TRACKBACK_PREFIX
247
+ end
248
+
249
+ def required_uri
250
+ TRACKBACK_URI
251
+ end
252
+
253
+ end
254
+
255
+ alias_method(:value, :content)
256
+ alias_method(:value=, :content=)
257
+
258
+ def initialize(*args)
259
+ if Utils.element_initialize_arguments?(args)
260
+ super
261
+ else
262
+ super()
263
+ self.content = args[0]
264
+ end
265
+ end
266
+
267
+ def full_name
268
+ tag_name_with_prefix(TRACKBACK_PREFIX)
269
+ end
270
+
271
+ end
272
+ end
273
+
274
+ class RDF
275
+ class Item; include TrackBackModel10; end
276
+ end
277
+
278
+ class Rss
279
+ class Channel
280
+ class Item; include TrackBackModel20; end
281
+ end
282
+ end
283
+
284
+ BaseTrackBackModel::ELEMENTS.each do |name|
285
+ class_name = Utils.to_class_name(name)
286
+ BaseListener.install_class_name(TRACKBACK_URI, name,
287
+ "TrackBack#{class_name}")
288
+ end
289
+
290
+ BaseTrackBackModel::ELEMENTS.collect! {|name| "#{TRACKBACK_PREFIX}_#{name}"}
291
+ end