1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rss/image.rb
kou 80861909e6 * lib/rss: backoported from HEAD.
* lib/rss: refactored.
  - gave a name to 'x'.
  - undef_method -> remove_method for avoiding a warning in ruby 1.6.


* lib/rss/parser.rb: @@setter -> @@setters.

* lib/rss/parser.rb
  (RSS::BaseListener.register_uri)
  (RSS::BaseListener.uri_registered?)
  (RSS::BaseListener.install_get_text_element):
  swapped the first argument and the second argument.

* lib/rss/taxonomy.rb: swapped the first argument and the second
  argument for RSS::BaseListener.install_get_text_element.
* lib/rss/image.rb: ditto.
* lib/rss/syndication.rb: ditto.
* lib/rss/dublincore.rb: ditto.
* lib/rss/parser.rb: ditto.
* lib/rss/1.0.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/0.9.rb: ditto.
* lib/rss/content.rb: ditto.

* lib/rss/parser.rb
  (RSS::BaseListener.install_setter)
  (RSS::BaseListener.register_uri): changed fallback way.

* lib/rss/parser.rb: added class name registry for complex model
  elements. (ex. have childlen elements, have some attributes and
  a child element and so on.)


* lib/rss/dublincore.rb: supported multiple Dublin Core items.
* lib/rss/maker/dublincore.rb: ditto.
* lib/rss/maker/image.rb: supproted new Dublin Core API.
* lib/rss/maker/base.rb: added default current_element implementation.
* lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
  moved to RSS::Utils.

* lib/rss/utils.rb (RSS::Utils.new_with_value_if_need):
  moved from RSS::TrackBackUtils.

* lib/rss/maker/image.rb: fixed invalid argument of
  add_need_initialize_variable bug.
* lib/rss/maker/trackback.rb: ditto.

* lib/rss/rss.rb (Hash#merge): added for ruby 1.6.
* lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil
  for date value.


* test/test_dublincore.rb: added tests for plural accessor and
  multiple Dublin Core items.

* test/test_setup_maker_1.0.rb: fixed swapped actual and expected
  values.

* test/rss/rss-assertions.rb (assert_multiple_dublin_core): added
  an assertion for testing multiple Dublin Core items.

* test/rss/test_maker_dc.rb (test_rss10_multiple): added a test
  for making multiple Dublin Core items.

* test/rss/test_maker_dc.rb (test_date): added a test for #date=
  and #dc_date=.


* sample/rss/tdiary_plugin/rss-recent.rb:
  new option: @options['rss-recent.use-image-link']:
  use image as link instread of text if available.

* sample/rss/tdiary_plugin/rss-recent.rb (RSS_RECENT_VERSION):
  0.0.5 -> 0.0.6.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-04-09 03:09:52 +00:00

216 lines
4.6 KiB
Ruby

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(IMAGE_URI, tag, "#{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 |uri, name|
send(name).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