Sha256: 01f69c1f07f435766f2e987f4a8745f7022347460edd682713817fbb77cf9a29
Contents?: true
Size: 1.72 KB
Versions: 1
Compression:
Stored size: 1.72 KB
Contents
# 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<Html2rss::Config::Stylesheet>] 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 # @return [String] the XML representation of the stylesheet def to_xml <<~XML <?xml-stylesheet href="#{href}" type="#{type}" media="#{media}"?> XML end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
html2rss-0.16.0 | lib/html2rss/rss_builder/stylesheet.rb |