# frozen_string_literal: false
require_relative "parser"
# RSS has three different versions. This module contains support for version
# 0.9.1[http://www.rssboard.org/rss-0-9-1-netscape].
# Producing our own RSS feeds is easy as well. Let's make a very basic feed:
# rss = RSS::Maker.make("0.91") do |maker|
# maker.channel.language = "en"
# maker.channel.author = "matz"
# 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.image.url = "http://www.ruby-lang.org/images/logo.gif"
# maker.image.title = "An image"
# 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
# As you can see, this is a very Builder-like DSL. This code will spit out an
# RSS 0.9 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.
def self.append_features(klass)
klass.install_must_call_validator('', "")
%w(channel).each do |name|
install_have_child_element(name, "", nil)
attr_writer :feed_version
alias_method(:rss_version, :feed_version)
alias_method(:rss_version=, :feed_version=)
def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
def setup_maker_elements(maker)
item.setup_maker(maker.items)
image.setup_maker(maker) if image
textinput.setup_maker(maker) if textinput
["version", true, "feed_version"],
["description", nil, :text],
["language", nil, :text],
["copyright", "?", :text],
["managingEditor", "?", :text],
["webMaster", "?", :text],
["pubDate", "?", :date, :rfc822],
["lastBuildDate", "?", :date, :rfc822],
["cloud", "?", :have_attribute],
["skipDays", "?", :have_child],
["skipHours", "?", :have_child],
["image", nil, :have_child],
["item", "*", :have_children],
["textInput", "?", :have_child],
].each do |name, occurs, type, *args|
__send__("install_#{type}_element", name, "", occurs, name, *args)
def setup_maker_elements(channel)
skip.__send__("#{key}s").each do |val|
target_skips = channel.__send__("skip#{key.capitalize}s")
new_target = target_skips.__send__("new_#{key}")
new_target.content = val.content
def not_need_to_call_setup_maker_variables
install_have_children_element(name, "", occurs)
if Utils.element_initialize_arguments?(args)
class SkipHours < Element
install_have_children_element(name, "", occurs)
if Utils.element_initialize_arguments?(args)
%w(url title link).each do |name|
install_text_element(name, "", nil)
install_text_element(name, "", "?", name, type)
if Utils.element_initialize_arguments?(args)
self.description = args[5]
["port", "", true, :integer],
["registerProcedure", "", true],
].each do |name, uri, required, type|
install_get_attribute(name, uri, required, type)
if Utils.element_initialize_arguments?(args)
self.registerProcedure = args[3]
["description", '?', :text],
["category", '*', :have_children, "categories"],
["source", '?', :have_child],
["enclosure", '?', :have_child],
].each do |tag, occurs, type, *args|
__send__("install_#{type}_element", tag, "", occurs, tag, *args)
if items.respond_to?("items")
# For backward compatibility
def setup_maker_element(item)
@enclosure.setup_maker(item) if @enclosure
@source.setup_maker(item) if @source
].each do |name, uri, required|
install_get_attribute(name, uri, required)
if Utils.element_initialize_arguments?(args)
def setup_maker_attributes(source)
class Enclosure < Element
["length", "", true, :integer],
].each do |name, uri, required, type|
install_get_attribute(name, uri, required, type)
if Utils.element_initialize_arguments?(args)
def setup_maker_attributes(enclosure)
enclosure.length = length
].each do |name, uri, required|
install_get_attribute(name, uri, required)
if Utils.element_initialize_arguments?(args)
def setup_maker_attributes(category)
category.content = content
class TextInput < Element
%w(title description name link).each do |name|
install_text_element(name, "", nil)
if Utils.element_initialize_arguments?(args)
self.description = args[1]
RSS09::ELEMENTS.each do |name|
BaseListener.install_get_text_element("", name, name)
def initial_start_rss(tag_name, prefix, attrs, ns)
check_ns(tag_name, prefix, ns, "", false)
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
@rss.do_validate = @do_validate
@rss.xml_stylesheets = @xml_stylesheets
pr = Proc.new do |text, tags|
@rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate