PageRenderTime 50ms CodeModel.GetById 33ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/agross/netopenspace
Ruby | 111 lines | 93 code | 18 blank | 0 comment | 2 complexity | 16d61a1966bd6e2b907d1ac79c33d450 MD5 | raw file
  1require 'rss/image'
  2require 'rss/maker/1.0'
  3require 'rss/maker/dublincore'
  4
  5module RSS
  6  module Maker
  7    module ImageItemModel
  8      def self.append_features(klass)
  9        super
 10
 11        name = "#{RSS::IMAGE_PREFIX}_item"
 12        klass.def_classed_element(name)
 13      end
 14
 15      def self.install_image_item(klass)
 16	klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
 17          class ImageItem < ImageItemBase
 18            DublinCoreModel.install_dublin_core(self)
 19          end
 20EOC
 21      end
 22
 23      class ImageItemBase < Base
 24        include Maker::DublinCoreModel
 25
 26        attr_accessor :about, :resource, :image_width, :image_height
 27        add_need_initialize_variable("about")
 28        add_need_initialize_variable("resource")
 29        add_need_initialize_variable("image_width")
 30        add_need_initialize_variable("image_height")
 31        alias width= image_width=
 32        alias width image_width
 33        alias height= image_height=
 34        alias height image_height
 35
 36        def have_required_values?
 37          @about
 38        end
 39
 40        def to_feed(feed, current)
 41          if current.respond_to?(:image_item=) and have_required_values?
 42            item = current.class::ImageItem.new
 43            setup_values(item)
 44            setup_other_elements(item)
 45            current.image_item = item
 46          end
 47        end
 48      end
 49    end
 50
 51    module ImageFaviconModel
 52      def self.append_features(klass)
 53        super
 54
 55        name = "#{RSS::IMAGE_PREFIX}_favicon"
 56        klass.def_classed_element(name)
 57      end
 58
 59      def self.install_image_favicon(klass)
 60	klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
 61          class ImageFavicon < ImageFaviconBase
 62            DublinCoreModel.install_dublin_core(self)
 63          end
 64        EOC
 65      end
 66
 67      class ImageFaviconBase < Base
 68        include Maker::DublinCoreModel
 69
 70        attr_accessor :about, :image_size
 71        add_need_initialize_variable("about")
 72        add_need_initialize_variable("image_size")
 73        alias size image_size
 74        alias size= image_size=
 75
 76        def have_required_values?
 77          @about and @image_size
 78        end
 79
 80        def to_feed(feed, current)
 81          if current.respond_to?(:image_favicon=) and have_required_values?
 82            favicon = current.class::ImageFavicon.new
 83            setup_values(favicon)
 84            setup_other_elements(favicon)
 85            current.image_favicon = favicon
 86          end
 87        end
 88      end
 89    end
 90
 91    class ChannelBase; include Maker::ImageFaviconModel; end
 92    
 93    class ItemsBase
 94      class ItemBase; include Maker::ImageItemModel; end
 95    end
 96
 97    makers.each do |maker|
 98      maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
 99        class Channel
100          ImageFaviconModel.install_image_favicon(self)
101        end
102
103        class Items
104          class Item
105            ImageItemModel.install_image_item(self)
106          end
107        end
108      EOC
109    end
110  end
111end