PageRenderTime 110ms CodeModel.GetById 71ms app.highlight 8ms RepoModel.GetById 29ms app.codeStats 1ms

/tools/Ruby/lib/ruby/1.8/rss/maker/trackback.rb

http://github.com/agross/netopenspace
Ruby | 61 lines | 52 code | 9 blank | 0 comment | 1 complexity | 1c7616c0face3428dc50e7941b46f8de MD5 | raw file
 1require 'rss/trackback'
 2require 'rss/maker/1.0'
 3require 'rss/maker/2.0'
 4
 5module RSS
 6  module Maker
 7    module TrackBackModel
 8      def self.append_features(klass)
 9        super
10
11        klass.def_other_element("#{RSS::TRACKBACK_PREFIX}_ping")
12        klass.def_classed_elements("#{RSS::TRACKBACK_PREFIX}_about", "value",
13                                   "TrackBackAbouts")
14      end
15
16      class TrackBackAboutsBase < Base
17        def_array_element("about", nil, "TrackBackAbout")
18
19        class TrackBackAboutBase < Base
20          attr_accessor :value
21          add_need_initialize_variable("value")
22          
23          alias_method(:resource, :value)
24          alias_method(:resource=, :value=)
25          alias_method(:content, :value)
26          alias_method(:content=, :value=)
27
28          def have_required_values?
29            @value
30          end
31
32          def to_feed(feed, current)
33            if current.respond_to?(:trackback_abouts) and have_required_values?
34              about = current.class::TrackBackAbout.new
35              setup_values(about)
36              setup_other_elements(about)
37              current.trackback_abouts << about
38            end
39          end
40        end
41      end
42    end
43
44    class ItemsBase
45      class ItemBase; include TrackBackModel; end
46    end
47
48    makers.each do |maker|
49      maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
50        class Items
51          class Item
52            class TrackBackAbouts < TrackBackAboutsBase
53              class TrackBackAbout < TrackBackAboutBase
54              end
55            end
56          end
57        end
58      EOC
59    end
60  end
61end