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,112 @@
1
+ # frozen_string_literal: false
2
+ require_relative '../image'
3
+ require_relative '1.0'
4
+ require_relative 'dublincore'
5
+
6
+ module RSS
7
+ module Maker
8
+ module ImageItemModel
9
+ def self.append_features(klass)
10
+ super
11
+
12
+ name = "#{RSS::IMAGE_PREFIX}_item"
13
+ klass.def_classed_element(name)
14
+ end
15
+
16
+ def self.install_image_item(klass)
17
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
18
+ class ImageItem < ImageItemBase
19
+ DublinCoreModel.install_dublin_core(self)
20
+ end
21
+ EOC
22
+ end
23
+
24
+ class ImageItemBase < Base
25
+ include Maker::DublinCoreModel
26
+
27
+ attr_accessor :about, :resource, :image_width, :image_height
28
+ add_need_initialize_variable("about")
29
+ add_need_initialize_variable("resource")
30
+ add_need_initialize_variable("image_width")
31
+ add_need_initialize_variable("image_height")
32
+ alias width= image_width=
33
+ alias width image_width
34
+ alias height= image_height=
35
+ alias height image_height
36
+
37
+ def have_required_values?
38
+ @about
39
+ end
40
+
41
+ def to_feed(feed, current)
42
+ if current.respond_to?(:image_item=) and have_required_values?
43
+ item = current.class::ImageItem.new
44
+ setup_values(item)
45
+ setup_other_elements(item)
46
+ current.image_item = item
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ module ImageFaviconModel
53
+ def self.append_features(klass)
54
+ super
55
+
56
+ name = "#{RSS::IMAGE_PREFIX}_favicon"
57
+ klass.def_classed_element(name)
58
+ end
59
+
60
+ def self.install_image_favicon(klass)
61
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
62
+ class ImageFavicon < ImageFaviconBase
63
+ DublinCoreModel.install_dublin_core(self)
64
+ end
65
+ EOC
66
+ end
67
+
68
+ class ImageFaviconBase < Base
69
+ include Maker::DublinCoreModel
70
+
71
+ attr_accessor :about, :image_size
72
+ add_need_initialize_variable("about")
73
+ add_need_initialize_variable("image_size")
74
+ alias size image_size
75
+ alias size= image_size=
76
+
77
+ def have_required_values?
78
+ @about and @image_size
79
+ end
80
+
81
+ def to_feed(feed, current)
82
+ if current.respond_to?(:image_favicon=) and have_required_values?
83
+ favicon = current.class::ImageFavicon.new
84
+ setup_values(favicon)
85
+ setup_other_elements(favicon)
86
+ current.image_favicon = favicon
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ class ChannelBase; include Maker::ImageFaviconModel; end
93
+
94
+ class ItemsBase
95
+ class ItemBase; include Maker::ImageItemModel; end
96
+ end
97
+
98
+ makers.each do |maker|
99
+ maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
100
+ class Channel
101
+ ImageFaviconModel.install_image_favicon(self)
102
+ end
103
+
104
+ class Items
105
+ class Item
106
+ ImageItemModel.install_image_item(self)
107
+ end
108
+ end
109
+ EOC
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,243 @@
1
+ # frozen_string_literal: false
2
+ require_relative '../itunes'
3
+ require_relative '2.0'
4
+
5
+ module RSS
6
+ module Maker
7
+ module ITunesBaseModel
8
+ def def_class_accessor(klass, name, type, *args)
9
+ name = name.gsub(/-/, "_").gsub(/^itunes_/, '')
10
+ full_name = "#{RSS::ITUNES_PREFIX}_#{name}"
11
+ case type
12
+ when nil
13
+ klass.def_other_element(full_name)
14
+ when :yes_other
15
+ def_yes_other_accessor(klass, full_name)
16
+ when :explicit_clean_other
17
+ def_explicit_clean_other_accessor(klass, full_name)
18
+ when :csv
19
+ def_csv_accessor(klass, full_name)
20
+ when :element, :attribute
21
+ recommended_attribute_name, = *args
22
+ klass_name = "ITunes#{Utils.to_class_name(name)}"
23
+ klass.def_classed_element(full_name, klass_name,
24
+ recommended_attribute_name)
25
+ when :elements
26
+ plural_name, recommended_attribute_name = args
27
+ plural_name ||= "#{name}s"
28
+ full_plural_name = "#{RSS::ITUNES_PREFIX}_#{plural_name}"
29
+ klass_name = "ITunes#{Utils.to_class_name(name)}"
30
+ plural_klass_name = "ITunes#{Utils.to_class_name(plural_name)}"
31
+ def_elements_class_accessor(klass, name, full_name, full_plural_name,
32
+ klass_name, plural_klass_name,
33
+ recommended_attribute_name)
34
+ end
35
+ end
36
+
37
+ def def_yes_other_accessor(klass, full_name)
38
+ klass.def_other_element(full_name)
39
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
40
+ def #{full_name}?
41
+ Utils::YesOther.parse(@#{full_name})
42
+ end
43
+ EOC
44
+ end
45
+
46
+ def def_explicit_clean_other_accessor(klass, full_name)
47
+ klass.def_other_element(full_name)
48
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
49
+ def #{full_name}?
50
+ Utils::ExplicitCleanOther.parse(#{full_name})
51
+ end
52
+ EOC
53
+ end
54
+
55
+ def def_csv_accessor(klass, full_name)
56
+ klass.def_csv_element(full_name)
57
+ end
58
+
59
+ def def_elements_class_accessor(klass, name, full_name, full_plural_name,
60
+ klass_name, plural_klass_name,
61
+ recommended_attribute_name=nil)
62
+ if recommended_attribute_name
63
+ klass.def_classed_elements(full_name, recommended_attribute_name,
64
+ plural_klass_name, full_plural_name)
65
+ else
66
+ klass.def_classed_element(full_plural_name, plural_klass_name)
67
+ end
68
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
69
+ def new_#{full_name}(text=nil)
70
+ #{full_name} = @#{full_plural_name}.new_#{name}
71
+ #{full_name}.text = text
72
+ if block_given?
73
+ yield #{full_name}
74
+ else
75
+ #{full_name}
76
+ end
77
+ end
78
+ EOC
79
+ end
80
+ end
81
+
82
+ module ITunesChannelModel
83
+ extend ITunesBaseModel
84
+
85
+ class << self
86
+ def append_features(klass)
87
+ super
88
+
89
+ ::RSS::ITunesChannelModel::ELEMENT_INFOS.each do |name, type, *args|
90
+ def_class_accessor(klass, name, type, *args)
91
+ end
92
+ end
93
+ end
94
+
95
+ class ITunesCategoriesBase < Base
96
+ def_array_element("category", "itunes_categories",
97
+ "ITunesCategory")
98
+ class ITunesCategoryBase < Base
99
+ attr_accessor :text
100
+ add_need_initialize_variable("text")
101
+ def_array_element("category", "itunes_categories",
102
+ "ITunesCategory")
103
+
104
+ def have_required_values?
105
+ text
106
+ end
107
+
108
+ alias_method :to_feed_for_categories, :to_feed
109
+ def to_feed(feed, current)
110
+ if text and current.respond_to?(:itunes_category)
111
+ new_item = current.class::ITunesCategory.new(text)
112
+ to_feed_for_categories(feed, new_item)
113
+ current.itunes_categories << new_item
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ class ITunesImageBase < Base
120
+ add_need_initialize_variable("href")
121
+ attr_accessor("href")
122
+
123
+ def to_feed(feed, current)
124
+ if @href and current.respond_to?(:itunes_image)
125
+ current.itunes_image ||= current.class::ITunesImage.new
126
+ current.itunes_image.href = @href
127
+ end
128
+ end
129
+ end
130
+
131
+ class ITunesOwnerBase < Base
132
+ %w(itunes_name itunes_email).each do |name|
133
+ add_need_initialize_variable(name)
134
+ attr_accessor(name)
135
+ end
136
+
137
+ def to_feed(feed, current)
138
+ if current.respond_to?(:itunes_owner=)
139
+ _not_set_required_variables = not_set_required_variables
140
+ if (required_variable_names - _not_set_required_variables).empty?
141
+ return
142
+ end
143
+
144
+ unless have_required_values?
145
+ raise NotSetError.new("maker.channel.itunes_owner",
146
+ _not_set_required_variables)
147
+ end
148
+ current.itunes_owner ||= current.class::ITunesOwner.new
149
+ current.itunes_owner.itunes_name = @itunes_name
150
+ current.itunes_owner.itunes_email = @itunes_email
151
+ end
152
+ end
153
+
154
+ private
155
+ def required_variable_names
156
+ %w(itunes_name itunes_email)
157
+ end
158
+ end
159
+ end
160
+
161
+ module ITunesItemModel
162
+ extend ITunesBaseModel
163
+
164
+ class << self
165
+ def append_features(klass)
166
+ super
167
+
168
+ ::RSS::ITunesItemModel::ELEMENT_INFOS.each do |name, type, *args|
169
+ def_class_accessor(klass, name, type, *args)
170
+ end
171
+ end
172
+ end
173
+
174
+ class ITunesDurationBase < Base
175
+ attr_reader :content
176
+ add_need_initialize_variable("content")
177
+
178
+ %w(hour minute second).each do |name|
179
+ attr_reader(name)
180
+ add_need_initialize_variable(name, 0)
181
+ end
182
+
183
+ def content=(content)
184
+ if content.nil?
185
+ @hour, @minute, @second, @content = nil
186
+ else
187
+ @hour, @minute, @second =
188
+ ::RSS::ITunesItemModel::ITunesDuration.parse(content)
189
+ @content = content
190
+ end
191
+ end
192
+
193
+ def hour=(hour)
194
+ @hour = Integer(hour)
195
+ update_content
196
+ end
197
+
198
+ def minute=(minute)
199
+ @minute = Integer(minute)
200
+ update_content
201
+ end
202
+
203
+ def second=(second)
204
+ @second = Integer(second)
205
+ update_content
206
+ end
207
+
208
+ def to_feed(feed, current)
209
+ if @content and current.respond_to?(:itunes_duration=)
210
+ current.itunes_duration ||= current.class::ITunesDuration.new
211
+ current.itunes_duration.content = @content
212
+ end
213
+ end
214
+
215
+ private
216
+ def update_content
217
+ components = [@hour, @minute, @second]
218
+ @content =
219
+ ::RSS::ITunesItemModel::ITunesDuration.construct(*components)
220
+ end
221
+ end
222
+ end
223
+
224
+ class ChannelBase
225
+ include Maker::ITunesChannelModel
226
+ class ITunesCategories < ITunesCategoriesBase
227
+ class ITunesCategory < ITunesCategoryBase
228
+ ITunesCategory = self
229
+ end
230
+ end
231
+
232
+ class ITunesImage < ITunesImageBase; end
233
+ class ITunesOwner < ITunesOwnerBase; end
234
+ end
235
+
236
+ class ItemsBase
237
+ class ItemBase
238
+ include Maker::ITunesItemModel
239
+ class ITunesDuration < ITunesDurationBase; end
240
+ end
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: false
2
+ require_relative '../slash'
3
+ require_relative '1.0'
4
+
5
+ module RSS
6
+ module Maker
7
+ module SlashModel
8
+ def self.append_features(klass)
9
+ super
10
+
11
+ ::RSS::SlashModel::ELEMENT_INFOS.each do |name, type|
12
+ full_name = "#{RSS::SLASH_PREFIX}_#{name}"
13
+ case type
14
+ when :csv_integer
15
+ klass.def_csv_element(full_name, :integer)
16
+ else
17
+ klass.def_other_element(full_name)
18
+ end
19
+ end
20
+
21
+ klass.module_eval do
22
+ alias_method(:slash_hit_parades, :slash_hit_parade)
23
+ alias_method(:slash_hit_parades=, :slash_hit_parade=)
24
+ end
25
+ end
26
+ end
27
+
28
+ class ItemsBase
29
+ class ItemBase
30
+ include SlashModel
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: false
2
+ require_relative '../syndication'
3
+ require_relative '1.0'
4
+
5
+ module RSS
6
+ module Maker
7
+ module SyndicationModel
8
+ def self.append_features(klass)
9
+ super
10
+
11
+ ::RSS::SyndicationModel::ELEMENTS.each do |name|
12
+ klass.def_other_element(name)
13
+ end
14
+ end
15
+ end
16
+
17
+ class ChannelBase; include SyndicationModel; end
18
+ end
19
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: false
2
+ require_relative '../taxonomy'
3
+ require_relative '1.0'
4
+ require_relative 'dublincore'
5
+
6
+ module RSS
7
+ module Maker
8
+ module TaxonomyTopicsModel
9
+ def self.append_features(klass)
10
+ super
11
+
12
+ klass.def_classed_element("#{RSS::TAXO_PREFIX}_topics",
13
+ "TaxonomyTopics")
14
+ end
15
+
16
+ def self.install_taxo_topics(klass)
17
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
18
+ class TaxonomyTopics < TaxonomyTopicsBase
19
+ def to_feed(feed, current)
20
+ if current.respond_to?(:taxo_topics)
21
+ topics = current.class::TaxonomyTopics.new
22
+ bag = topics.Bag
23
+ @resources.each do |resource|
24
+ bag.lis << RDF::Bag::Li.new(resource)
25
+ end
26
+ current.taxo_topics = topics
27
+ end
28
+ end
29
+ end
30
+ EOC
31
+ end
32
+
33
+ class TaxonomyTopicsBase < Base
34
+ attr_reader :resources
35
+ def_array_element("resource")
36
+ remove_method :new_resource
37
+ end
38
+ end
39
+
40
+ module TaxonomyTopicModel
41
+ def self.append_features(klass)
42
+ super
43
+
44
+ class_name = "TaxonomyTopics"
45
+ klass.def_classed_elements("#{TAXO_PREFIX}_topic", "value", class_name)
46
+ end
47
+
48
+ def self.install_taxo_topic(klass)
49
+ klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
50
+ class TaxonomyTopics < TaxonomyTopicsBase
51
+ class TaxonomyTopic < TaxonomyTopicBase
52
+ DublinCoreModel.install_dublin_core(self)
53
+ TaxonomyTopicsModel.install_taxo_topics(self)
54
+
55
+ def to_feed(feed, current)
56
+ if current.respond_to?(:taxo_topics)
57
+ topic = current.class::TaxonomyTopic.new(value)
58
+ topic.taxo_link = value
59
+ taxo_topics.to_feed(feed, topic) if taxo_topics
60
+ current.taxo_topics << topic
61
+ setup_other_elements(feed, topic)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ EOC
67
+ end
68
+
69
+ class TaxonomyTopicsBase < Base
70
+ def_array_element("topic", nil, "TaxonomyTopic")
71
+ alias_method(:new_taxo_topic, :new_topic) # For backward compatibility
72
+
73
+ class TaxonomyTopicBase < Base
74
+ include DublinCoreModel
75
+ include TaxonomyTopicsModel
76
+
77
+ attr_accessor :value
78
+ add_need_initialize_variable("value")
79
+ alias_method(:taxo_link, :value)
80
+ alias_method(:taxo_link=, :value=)
81
+
82
+ def have_required_values?
83
+ @value
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ class RSSBase
90
+ include TaxonomyTopicModel
91
+ end
92
+
93
+ class ChannelBase
94
+ include TaxonomyTopicsModel
95
+ end
96
+
97
+ class ItemsBase
98
+ class ItemBase
99
+ include TaxonomyTopicsModel
100
+ end
101
+ end
102
+
103
+ makers.each do |maker|
104
+ maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
105
+ TaxonomyTopicModel.install_taxo_topic(self)
106
+
107
+ class Channel
108
+ TaxonomyTopicsModel.install_taxo_topics(self)
109
+ end
110
+
111
+ class Items
112
+ class Item
113
+ TaxonomyTopicsModel.install_taxo_topics(self)
114
+ end
115
+ end
116
+ EOC
117
+ end
118
+ end
119
+ end