summaryrefslogtreecommitdiff
path: root/lib/rss
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-03 15:31:58 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-03 15:31:58 +0000
commit73c9ac28d42dae5c8dd1fc68baa83422733581ea (patch)
treedca405bb64ac64608df40f6c7ee664eeb89febd1 /lib/rss
parentca1f8939daaf49f0ae4c6a0fc9a378bc095c99a7 (diff)
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss')
-rw-r--r--lib/rss/image.rb216
-rw-r--r--lib/rss/maker/image.rb136
2 files changed, 352 insertions, 0 deletions
diff --git a/lib/rss/image.rb b/lib/rss/image.rb
new file mode 100644
index 0000000000..9cc3c73018
--- /dev/null
+++ b/lib/rss/image.rb
@@ -0,0 +1,216 @@
+require 'rss/1.0'
+require 'rss/dublincore'
+
+module RSS
+
+ IMAGE_PREFIX = 'image'
+ IMAGE_URI = 'http://web.resource.org/rss/1.0/modules/image/'
+
+ RDF.install_ns(IMAGE_PREFIX, IMAGE_URI)
+
+ module ImageModelUtils
+ def validate_one_tag_name(name, tags)
+ invalid = tags.find {|tag| tag != name}
+ raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
+ raise TooMuchTagError.new(name, tag_name) if tags.size > 1
+ end
+ end
+
+ module ImageItemModel
+ include ImageModelUtils
+ extend BaseModel
+
+ def self.append_features(klass)
+ super
+
+ klass.install_have_child_element("#{IMAGE_PREFIX}_item")
+ end
+
+ def image_validate(tags)
+ validate_one_tag_name("item", tags)
+ end
+
+ class Item < Element
+ include RSS10
+ include DublinCoreModel
+
+ class << self
+ def required_prefix
+ IMAGE_PREFIX
+ end
+
+ def required_uri
+ IMAGE_URI
+ end
+ end
+
+ [
+ ["about", ::RSS::RDF::URI, true],
+ ["resource", ::RSS::RDF::URI, false],
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ %w(width height).each do |tag|
+ full_name = "#{IMAGE_PREFIX}_#{tag}"
+ install_text_element(full_name)
+ BaseListener.install_get_text_element(tag, IMAGE_URI, "#{full_name}=")
+ end
+
+ def initialize(about=nil, resource=nil)
+ super()
+ @about = about
+ @resource = resource
+ end
+
+ def full_name
+ tag_name_with_prefix(IMAGE_PREFIX)
+ end
+
+ def to_s(need_convert=true, indent=calc_indent)
+ rv = tag(indent) do |next_indent|
+ [
+ other_element(false, next_indent),
+ ]
+ end
+ rv = convert(rv) if need_convert
+ rv
+ end
+
+ alias _image_width= image_width=
+ def image_width=(new_value)
+ if @do_validate
+ self._image_width = Integer(new_value)
+ else
+ self._image_width = new_value.to_i
+ end
+ end
+
+ alias _image_height= image_height=
+ def image_height=(new_value)
+ if @do_validate
+ self._image_height = Integer(new_value)
+ else
+ self._image_height = new_value.to_i
+ end
+ end
+
+ alias width= image_width=
+ alias width image_width
+ alias height= image_height=
+ alias height image_height
+
+ private
+ def _tags
+ [
+ [IMAGE_URI, 'width'],
+ [IMAGE_URI, 'height'],
+ ].delete_if do |x|
+ send(x[1]).nil?
+ end
+ end
+
+ def _attrs
+ [
+ ["#{::RSS::RDF::PREFIX}:about", true, "about"],
+ ["#{::RSS::RDF::PREFIX}:resource", false, "resource"],
+ ]
+ end
+
+ def maker_target(target)
+ target.image_item
+ end
+
+ def setup_maker_attributes(item)
+ item.about = self.about
+ item.resource = self.resource
+ end
+ end
+ end
+
+ module ImageFaviconModel
+ include ImageModelUtils
+ extend BaseModel
+
+ def self.append_features(klass)
+ super
+
+ unless klass.class == Module
+ klass.install_have_child_element("#{IMAGE_PREFIX}_favicon")
+ end
+ end
+
+ def image_validate(tags)
+ validate_one_tag_name("favicon", tags)
+ end
+
+ class Favicon < Element
+ include RSS10
+ include DublinCoreModel
+
+ class << self
+ def required_prefix
+ IMAGE_PREFIX
+ end
+
+ def required_uri
+ IMAGE_URI
+ end
+ end
+
+ [
+ ["about", ::RSS::RDF::URI, true],
+ ["size", IMAGE_URI, true],
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ alias image_size= size=
+ alias image_size size
+
+ def initialize(about=nil, size=nil)
+ super()
+ @about = about
+ @size = size
+ end
+
+ def full_name
+ tag_name_with_prefix(IMAGE_PREFIX)
+ end
+
+ def to_s(need_convert=true, indent=calc_indent)
+ rv = tag(indent) do |next_indent|
+ [
+ other_element(false, next_indent),
+ ]
+ end
+ rv = convert(rv) if need_convert
+ rv
+ end
+
+ private
+ def _attrs
+ [
+ ["#{::RSS::RDF::PREFIX}:about", true, "about"],
+ ["#{IMAGE_PREFIX}:size", true, "size"],
+ ]
+ end
+
+ def maker_target(target)
+ target.image_favicon
+ end
+
+ def setup_maker_attributes(favicon)
+ favicon.about = self.about
+ favicon.size = self.size
+ end
+ end
+
+ end
+
+ class RDF
+ class Channel; include ImageFaviconModel; end
+ class Item; include ImageItemModel; end
+ end
+
+end
diff --git a/lib/rss/maker/image.rb b/lib/rss/maker/image.rb
new file mode 100644
index 0000000000..98d59f733c
--- /dev/null
+++ b/lib/rss/maker/image.rb
@@ -0,0 +1,136 @@
+require 'rss/image'
+require 'rss/maker/1.0'
+require 'rss/maker/dublincore'
+
+module RSS
+ module Maker
+ module ImageItemModel
+ def self.append_features(klass)
+ super
+
+ name = "#{RSS::IMAGE_PREFIX}_item"
+ klass.add_need_initialize_variable(name, "make_#{name}")
+ klass.add_other_element(name)
+ klass.__send__(:attr_reader, name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__)
+ def setup_#{name}(rss, current)
+ if @#{name}
+ @#{name}.to_rss(rss, current)
+ end
+ end
+
+ def make_#{name}
+ self.class::#{Utils.to_class_name(name)}.new(@maker)
+ end
+EOC
+ end
+
+ class ImageItemBase
+ include Base
+ include Maker::DublinCoreModel
+
+ attr_accessor :about, :resource, :image_width, :image_height
+ add_need_initialize_variable(:about, :resource)
+ add_need_initialize_variable(:image_width, :image_height)
+ alias width= image_width=
+ alias width image_width
+ alias height= image_height=
+ alias height image_height
+
+ def have_required_values?
+ @about
+ end
+ end
+ end
+
+ module ImageFaviconModel
+ def self.append_features(klass)
+ super
+
+ name = "#{RSS::IMAGE_PREFIX}_favicon"
+ klass.add_need_initialize_variable(name, "make_#{name}")
+ klass.add_other_element(name)
+ klass.__send__(:attr_reader, name)
+ klass.module_eval(<<-EOC, __FILE__, __LINE__)
+ def setup_#{name}(rss, current)
+ if @#{name}
+ @#{name}.to_rss(rss, current)
+ end
+ end
+
+ def make_#{name}
+ self.class::#{Utils.to_class_name(name)}.new(@maker)
+ end
+EOC
+ end
+
+ class ImageFaviconBase
+ include Base
+ include Maker::DublinCoreModel
+
+ attr_accessor :about, :image_size
+ add_need_initialize_variable(:about, :image_size)
+ alias size image_size
+ alias size= image_size=
+
+ def have_required_values?
+ @about and @image_size
+ end
+ end
+ end
+
+ class ChannelBase; include Maker::ImageFaviconModel; end
+
+ class ItemsBase
+ class ItemBase; include Maker::ImageItemModel; end
+ end
+
+ class RSS10
+ class Items
+ class Item
+ class ImageItem < ImageItemBase
+ def to_rss(rss, current)
+ if @about
+ item = ::RSS::ImageItemModel::Item.new(@about, @resource)
+ setup_values(item)
+ current.image_item = item
+ end
+ end
+ end
+ end
+ end
+
+ class Channel
+ class ImageFavicon < ImageFaviconBase
+ def to_rss(rss, current)
+ if @about and @image_size
+ args = [@about, @image_size]
+ favicon = ::RSS::ImageFaviconModel::Favicon.new(*args)
+ setup_values(favicon)
+ current.image_favicon = favicon
+ end
+ end
+ end
+ end
+ end
+
+ class RSS09
+ class Items
+ class Item
+ class ImageItem < ImageItemBase
+ def to_rss(*args)
+ end
+ end
+ end
+ end
+
+ class Channel
+ class ImageFavicon < ImageFaviconBase
+ def to_rss(*args)
+ end
+ end
+ end
+ end
+
+ end
+end