~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2006-05-08 22:23:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060508222312-w2wqeaz030ifi59j
Tags: 1.9.0+20060423-3ubuntu1
* Resynchronized with Debian.
* Only change from Debian is the addition of
  debian/patches/903_sparc_fix_define.patch to fix illegal instructions
  at runtime on sparc. (change from 1.9.0+20050921-1ubuntu1)

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
          taxo_topic
 
111
        end
 
112
 
 
113
        def to_rss(rss, current)
 
114
          @taxo_topics.each do |taxo_topic|
 
115
            taxo_topic.to_rss(rss, current)
 
116
          end
 
117
        end
 
118
        
 
119
        class TaxonomyTopicBase
 
120
          include Base
 
121
          include DublinCoreModel
 
122
          include TaxonomyTopicsModel
 
123
          
 
124
          attr_accessor :value
 
125
          add_need_initialize_variable("value")
 
126
          alias_method(:taxo_link, :value)
 
127
          alias_method(:taxo_link=, :value=)
 
128
          
 
129
          def have_required_values?
 
130
            @value
 
131
          end
 
132
        end
 
133
      end
 
134
    end
 
135
 
 
136
    class RSSBase
 
137
      include TaxonomyTopicModel
 
138
    end
 
139
    
 
140
    class ChannelBase
 
141
      include TaxonomyTopicsModel
 
142
    end
 
143
    
 
144
    class ItemsBase
 
145
      class ItemBase
 
146
        include TaxonomyTopicsModel
 
147
      end
 
148
    end
 
149
 
 
150
    class RSS10
 
151
      TaxonomyTopicModel.install_taxo_topic(self)
 
152
      
 
153
      class Channel
 
154
        TaxonomyTopicsModel.install_taxo_topics(self)
 
155
      end
 
156
 
 
157
      class Items
 
158
        class Item
 
159
          TaxonomyTopicsModel.install_taxo_topics(self)
 
160
        end
 
161
      end
 
162
    end
 
163
    
 
164
    class RSS09
 
165
      TaxonomyTopicModel.install_taxo_topic(self)
 
166
      
 
167
      class Channel
 
168
        TaxonomyTopicsModel.install_taxo_topics(self)
 
169
      end
 
170
 
 
171
      class Items
 
172
        class Item
 
173
          TaxonomyTopicsModel.install_taxo_topics(self)
 
174
        end
 
175
      end
 
176
    end
 
177
  end
 
178
end