~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/rss/maker/taxonomy.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

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