1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
require 'rss/taxonomy'
require 'rss/maker/1.0'
require 'rss/maker/dublincore'
module RSS
module Maker
module TaxoTopicsModel
def self.append_features(klass)
super
klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
klass.add_other_element("taxo_topics")
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
attr_reader :taxo_topics
def make_taxo_topics
self.class::TaxoTopics.new(@maker)
end
def setup_taxo_topics(rss, current)
@taxo_topics.to_rss(rss, current)
end
EOC
end
def self.install_taxo_topics(klass)
klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
class TaxoTopics < TaxoTopicsBase
def to_rss(rss, current)
if current.respond_to?(:taxo_topics)
topics = current.class::TaxoTopics.new
bag = topics.Bag
@resources.each do |resource|
bag.lis << RDF::Bag::Li.new(resource)
end
current.taxo_topics = topics
end
end
end
EOC
end
class TaxoTopicsBase
include Base
attr_reader :resources
def_array_element("resources")
end
end
module TaxoTopicModel
def self.append_features(klass)
super
klass.add_need_initialize_variable("taxo_topics", "make_taxo_topics")
klass.add_other_element("taxo_topics")
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
attr_reader :taxo_topics
def make_taxo_topics
self.class::TaxoTopics.new(@maker)
end
def setup_taxo_topics(rss, current)
@taxo_topics.to_rss(rss, current)
end
def taxo_topic
@taxo_topics[0] and @taxo_topics[0].value
end
def taxo_topic=(new_value)
@taxo_topic[0] = self.class::TaxoTopic.new(self)
@taxo_topic[0].value = new_value
end
EOC
end
def self.install_taxo_topic(klass)
klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
class TaxoTopics < TaxoTopicsBase
class TaxoTopic < TaxoTopicBase
DublinCoreModel.install_dublin_core(self)
TaxoTopicsModel.install_taxo_topics(self)
def to_rss(rss, current)
if current.respond_to?(:taxo_topics)
topic = current.class::TaxoTopic.new(value)
topic.taxo_link = value
taxo_topics.to_rss(rss, topic) if taxo_topics
current.taxo_topics << topic
setup_other_elements(rss)
end
end
def current_element(rss)
super.taxo_topics.last
end
end
end
EOC
end
class TaxoTopicsBase
include Base
def_array_element("taxo_topics")
def new_taxo_topic
taxo_topic = self.class::TaxoTopic.new(self)
@taxo_topics << taxo_topic
taxo_topic
end
def to_rss(rss, current)
@taxo_topics.each do |taxo_topic|
taxo_topic.to_rss(rss, current)
end
end
class TaxoTopicBase
include Base
include DublinCoreModel
include TaxoTopicsModel
attr_accessor :value
add_need_initialize_variable("value")
alias_method(:taxo_link, :value)
alias_method(:taxo_link=, :value=)
def have_required_values?
@value
end
end
end
end
class RSSBase
include TaxoTopicModel
end
class ChannelBase
include TaxoTopicsModel
end
class ItemsBase
class ItemBase
include TaxoTopicsModel
end
end
class RSS10
TaxoTopicModel.install_taxo_topic(self)
class Channel
TaxoTopicsModel.install_taxo_topics(self)
end
class Items
class Item
TaxoTopicsModel.install_taxo_topics(self)
end
end
end
class RSS09
TaxoTopicModel.install_taxo_topic(self)
class Channel
TaxoTopicsModel.install_taxo_topics(self)
end
class Items
class Item
TaxoTopicsModel.install_taxo_topics(self)
end
end
end
end
end
|