# frozen_string_literal: true
module Html2rss
module RssBuilder
##
# Represents a stylesheet.
class Stylesheet
class << self
##
# Adds the stylesheet XML tags to the RSS.
#
# @param maker [RSS::Maker::RSS20] RSS maker object.
# @param stylesheets [Array] Array of stylesheet configurations.
# @return [nil]
def add(maker, stylesheets)
stylesheets.each do |stylesheet|
add_stylesheet(maker, stylesheet)
end
end
private
##
# Adds a single Stylesheet to the RSS.
#
# @param maker [RSS::Maker::RSS20] RSS maker object.
# @param stylesheet [Html2rss::Config::Stylesheet] Stylesheet configuration.
# @return [nil]
def add_stylesheet(maker, stylesheet)
maker.xml_stylesheets.new_xml_stylesheet do |xss|
xss.href = stylesheet.href
xss.type = stylesheet.type
xss.media = stylesheet.media
end
end
end
TYPES = ['text/css', 'text/xsl'].freeze
def initialize(href:, type:, media: 'all')
raise ArgumentError, 'stylesheet.href must be a String' unless href.is_a?(String)
raise ArgumentError, 'stylesheet.type invalid' unless TYPES.include?(type)
raise ArgumentError, 'stylesheet.media must be a String' unless media.is_a?(String)
@href = href
@type = type
@media = media
end
attr_reader :href, :type, :media
end
end
end