2004-01-28 10:19:56 -05:00
|
|
|
require "rss/parser"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
module RSS
|
|
|
|
|
2013-08-06 09:36:31 -04:00
|
|
|
##
|
|
|
|
# = RSS 1.0 support
|
|
|
|
#
|
|
|
|
# RSS has three different versions. This module contains support for version
|
|
|
|
# 1.0[http://web.resource.org/rss/1.0/]
|
|
|
|
#
|
|
|
|
# == Producing RSS 1.0
|
|
|
|
#
|
|
|
|
# Producing our own RSS feeds is easy as well. Let's make a very basic feed:
|
|
|
|
#
|
|
|
|
# require "rss"
|
|
|
|
#
|
|
|
|
# rss = RSS::Maker.make("1.0") do |maker|
|
|
|
|
# maker.channel.language = "en"
|
|
|
|
# maker.channel.author = "matz"
|
|
|
|
# maker.channel.about = "About my feed."
|
|
|
|
# maker.channel.updated = Time.now.to_s
|
|
|
|
# maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
|
|
|
|
# maker.channel.title = "Example Feed"
|
|
|
|
# maker.channel.description = "A longer description of my feed."
|
|
|
|
# maker.items.new_item do |item|
|
|
|
|
# item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
|
|
|
|
# item.title = "Ruby 1.9.2-p136 is released"
|
|
|
|
# item.updated = Time.now.to_s
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# puts rss
|
|
|
|
#
|
|
|
|
# As you can see, this is a very Builder-like DSL. This code will spit out an
|
|
|
|
# RSS 1.0 feed with one item. If we needed a second item, we'd make another
|
|
|
|
# block with maker.items.new_item and build a second one.
|
2004-10-16 00:51:15 -04:00
|
|
|
module RSS10
|
|
|
|
NSPOOL = {}
|
|
|
|
ELEMENTS = []
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
klass.install_must_call_validator('', ::RSS::URI)
|
|
|
|
end
|
2004-07-06 13:43:05 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class RDF < Element
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include RSS10
|
|
|
|
include RootElementMixin
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class << self
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
@tag_name = 'RDF'
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
PREFIX = 'rdf'
|
|
|
|
URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
install_ns('', ::RSS::URI)
|
|
|
|
install_ns(PREFIX, URI)
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
[
|
|
|
|
["channel", nil],
|
|
|
|
["image", "?"],
|
2007-03-17 06:13:25 -04:00
|
|
|
["item", "+", :children],
|
2004-10-16 00:51:15 -04:00
|
|
|
["textinput", "?"],
|
2007-03-17 06:13:25 -04:00
|
|
|
].each do |tag, occurs, type|
|
|
|
|
type ||= :child
|
|
|
|
__send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
alias_method(:rss_version, :feed_version)
|
2004-10-16 00:51:15 -04:00
|
|
|
def initialize(version=nil, encoding=nil, standalone=nil)
|
|
|
|
super('1.0', version, encoding, standalone)
|
2007-03-17 06:13:25 -04:00
|
|
|
@feed_type = "rss"
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
|
2005-11-17 03:42:13 -05:00
|
|
|
class Li < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-17 03:42:13 -05:00
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
["resource", [URI, ""], true]
|
2005-11-17 03:42:13 -05:00
|
|
|
].each do |name, uri, required|
|
|
|
|
install_get_attribute(name, uri, required)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2005-11-17 03:42:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Seq < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
2005-11-17 03:42:13 -05:00
|
|
|
Li = ::RSS::RDF::Li
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@tag_name = 'Seq'
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_children_element("li", URI, "*")
|
2004-10-16 00:51:15 -04:00
|
|
|
install_must_call_validator('rdf', ::RSS::RDF::URI)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
@li = args[0] if args[0]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-11-19 03:25:25 -05:00
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-23 04:24:17 -05:00
|
|
|
def setup_maker(target)
|
|
|
|
lis.each do |li|
|
|
|
|
target << li.resource
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2005-11-17 03:42:13 -05:00
|
|
|
class Bag < Element
|
2004-10-16 00:51:15 -04:00
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
2005-11-17 03:42:13 -05:00
|
|
|
Li = ::RSS::RDF::Li
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class << self
|
|
|
|
def required_uri
|
|
|
|
URI
|
|
|
|
end
|
|
|
|
end
|
2005-11-17 03:42:13 -05:00
|
|
|
|
|
|
|
@tag_name = 'Bag'
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_children_element("li", URI, "*")
|
|
|
|
install_must_call_validator('rdf', URI)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
@li = args[0] if args[0]
|
2005-11-17 03:42:13 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-11-19 03:25:25 -05:00
|
|
|
|
|
|
|
def full_name
|
|
|
|
tag_name_with_prefix(PREFIX)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-23 04:24:17 -05:00
|
|
|
def setup_maker(target)
|
|
|
|
lis.each do |li|
|
|
|
|
target << li.resource
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Channel < Element
|
|
|
|
|
|
|
|
include RSS10
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-02-02 08:00:31 -05:00
|
|
|
[
|
2004-10-16 00:51:15 -04:00
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
[
|
2007-03-17 06:13:25 -04:00
|
|
|
['title', nil, :text],
|
|
|
|
['link', nil, :text],
|
|
|
|
['description', nil, :text],
|
|
|
|
['image', '?', :have_child],
|
|
|
|
['items', nil, :have_child],
|
|
|
|
['textinput', '?', :have_child],
|
|
|
|
].each do |tag, occurs, type|
|
|
|
|
__send__("install_#{type}_element", tag, ::RSS::URI, occurs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.channel
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-27 03:47:28 -05:00
|
|
|
def setup_maker_attributes(channel)
|
2005-08-11 00:08:05 -04:00
|
|
|
channel.about = about
|
2004-11-27 03:47:28 -05:00
|
|
|
end
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Image < Element
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["resource", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Textinput < Element
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["resource", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.resource = args[0]
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class Items < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
Seq = ::RSS::RDF::Seq
|
|
|
|
|
|
|
|
class << self
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_have_child_element("Seq", URI, nil)
|
|
|
|
install_must_call_validator('rdf', URI)
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.Seq = args[0]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
self.Seq ||= Seq.new
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2005-11-17 04:01:22 -05:00
|
|
|
def resources
|
|
|
|
if @Seq
|
|
|
|
@Seq.lis.collect do |li|
|
|
|
|
li.resource
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Image < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(title url link).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, ::RSS::URI, nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.image
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Item < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["title", nil],
|
|
|
|
["link", nil],
|
|
|
|
["description", "?"],
|
|
|
|
].each do |tag, occurs|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(tag, ::RSS::URI, occurs)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
private
|
2005-11-23 04:24:17 -05:00
|
|
|
def maker_target(items)
|
|
|
|
if items.respond_to?("items")
|
|
|
|
# For backward compatibility
|
|
|
|
items = items.items
|
|
|
|
end
|
|
|
|
items.new_item
|
2004-11-27 03:47:28 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Textinput < Element
|
|
|
|
|
|
|
|
include RSS10
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def required_uri
|
|
|
|
::RSS::URI
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
[
|
|
|
|
["about", URI, true]
|
|
|
|
].each do |name, uri, required|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_get_attribute(name, uri, required, nil, nil,
|
|
|
|
"#{PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(title description name link).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, ::RSS::URI, nil)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def initialize(*args)
|
|
|
|
if Utils.element_initialize_arguments?(args)
|
|
|
|
super
|
|
|
|
else
|
|
|
|
super()
|
|
|
|
self.about = args[0]
|
2004-11-19 03:25:25 -05:00
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2004-11-27 03:47:28 -05:00
|
|
|
def maker_target(maker)
|
|
|
|
maker.textinput
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
RSS10::ELEMENTS.each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
BaseListener.install_get_text_element(URI, name, name)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module ListenerMixin
|
|
|
|
private
|
2007-03-17 06:13:25 -04:00
|
|
|
def initial_start_RDF(tag_name, prefix, attrs, ns)
|
2009-05-16 05:25:59 -04:00
|
|
|
check_ns(tag_name, prefix, ns, RDF::URI, false)
|
2004-10-16 00:51:15 -04:00
|
|
|
|
|
|
|
@rss = RDF.new(@version, @encoding, @standalone)
|
|
|
|
@rss.do_validate = @do_validate
|
|
|
|
@rss.xml_stylesheets = @xml_stylesheets
|
|
|
|
@last_element = @rss
|
2007-03-17 06:13:25 -04:00
|
|
|
pr = Proc.new do |text, tags|
|
|
|
|
@rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
|
|
|
|
end
|
|
|
|
@proc_stack.push(pr)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
|
|
|
end
|
2004-03-21 04:20:47 -05:00
|
|
|
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|