[18425] | 1 | require 'rss/trackback'
|
---|
| 2 | require 'rss/maker/1.0'
|
---|
| 3 | require 'rss/maker/2.0'
|
---|
| 4 |
|
---|
| 5 | module RSS
|
---|
| 6 | module Maker
|
---|
| 7 | module TrackBackModel
|
---|
| 8 | def self.append_features(klass)
|
---|
| 9 | super
|
---|
| 10 |
|
---|
| 11 | name = "#{RSS::TRACKBACK_PREFIX}_ping"
|
---|
| 12 | klass.add_need_initialize_variable(name)
|
---|
| 13 | klass.add_other_element(name)
|
---|
| 14 | klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
|
---|
| 15 | attr_accessor :#{name}
|
---|
| 16 | def setup_#{name}(rss, current)
|
---|
| 17 | if #{name} and current.respond_to?(:#{name}=)
|
---|
| 18 | current.#{name} = #{name}
|
---|
| 19 | end
|
---|
| 20 | end
|
---|
| 21 | EOC
|
---|
| 22 |
|
---|
| 23 | name = "#{RSS::TRACKBACK_PREFIX}_abouts"
|
---|
| 24 | klass.add_need_initialize_variable(name, "make_#{name}")
|
---|
| 25 | klass.add_other_element(name)
|
---|
| 26 | klass.module_eval(<<-EOC, __FILE__, __LINE__+1)
|
---|
| 27 | attr_accessor :#{name}
|
---|
| 28 | def make_#{name}
|
---|
| 29 | self.class::TrackBackAbouts.new(self)
|
---|
| 30 | end
|
---|
| 31 |
|
---|
| 32 | def setup_#{name}(rss, current)
|
---|
| 33 | @#{name}.to_rss(rss, current)
|
---|
| 34 | end
|
---|
| 35 | EOC
|
---|
| 36 | end
|
---|
| 37 |
|
---|
| 38 | class TrackBackAboutsBase
|
---|
| 39 | include Base
|
---|
| 40 |
|
---|
| 41 | def_array_element("abouts")
|
---|
| 42 |
|
---|
| 43 | def new_about
|
---|
| 44 | about = self.class::TrackBackAbout.new(@maker)
|
---|
| 45 | @abouts << about
|
---|
| 46 | if block_given?
|
---|
| 47 | yield about
|
---|
| 48 | else
|
---|
| 49 | about
|
---|
| 50 | end
|
---|
| 51 | end
|
---|
| 52 |
|
---|
| 53 | def to_rss(rss, current)
|
---|
| 54 | @abouts.each do |about|
|
---|
| 55 | about.to_rss(rss, current)
|
---|
| 56 | end
|
---|
| 57 | end
|
---|
| 58 |
|
---|
| 59 | class TrackBackAboutBase
|
---|
| 60 | include Base
|
---|
| 61 |
|
---|
| 62 | attr_accessor :value
|
---|
| 63 | add_need_initialize_variable("value")
|
---|
| 64 |
|
---|
| 65 | alias_method(:resource, :value)
|
---|
| 66 | alias_method(:resource=, :value=)
|
---|
| 67 | alias_method(:content, :value)
|
---|
| 68 | alias_method(:content=, :value=)
|
---|
| 69 |
|
---|
| 70 | def have_required_values?
|
---|
| 71 | @value
|
---|
| 72 | end
|
---|
| 73 |
|
---|
| 74 | end
|
---|
| 75 | end
|
---|
| 76 | end
|
---|
| 77 |
|
---|
| 78 | class ItemsBase
|
---|
| 79 | class ItemBase; include TrackBackModel; end
|
---|
| 80 | end
|
---|
| 81 |
|
---|
| 82 | class RSS10
|
---|
| 83 | class Items
|
---|
| 84 | class Item
|
---|
| 85 | class TrackBackAbouts < TrackBackAboutsBase
|
---|
| 86 | class TrackBackAbout < TrackBackAboutBase
|
---|
| 87 | def to_rss(rss, current)
|
---|
| 88 | if resource
|
---|
| 89 | about = ::RSS::TrackBackModel10::TrackBackAbout.new(resource)
|
---|
| 90 | current.trackback_abouts << about
|
---|
| 91 | end
|
---|
| 92 | end
|
---|
| 93 | end
|
---|
| 94 | end
|
---|
| 95 | end
|
---|
| 96 | end
|
---|
| 97 | end
|
---|
| 98 |
|
---|
| 99 | class RSS09
|
---|
| 100 | class Items
|
---|
| 101 | class Item
|
---|
| 102 | class TrackBackAbouts < TrackBackAboutsBase
|
---|
| 103 | def to_rss(*args)
|
---|
| 104 | end
|
---|
| 105 | class TrackBackAbout < TrackBackAboutBase
|
---|
| 106 | end
|
---|
| 107 | end
|
---|
| 108 | end
|
---|
| 109 | end
|
---|
| 110 | end
|
---|
| 111 |
|
---|
| 112 | class RSS20
|
---|
| 113 | class Items
|
---|
| 114 | class Item
|
---|
| 115 | class TrackBackAbouts < TrackBackAboutsBase
|
---|
| 116 | class TrackBackAbout < TrackBackAboutBase
|
---|
| 117 | def to_rss(rss, current)
|
---|
| 118 | if content
|
---|
| 119 | about = ::RSS::TrackBackModel20::TrackBackAbout.new(content)
|
---|
| 120 | current.trackback_abouts << about
|
---|
| 121 | end
|
---|
| 122 | end
|
---|
| 123 | end
|
---|
| 124 | end
|
---|
| 125 | end
|
---|
| 126 | end
|
---|
| 127 | end
|
---|
| 128 |
|
---|
| 129 | end
|
---|
| 130 | end
|
---|