Sha256: 112850a22be46e39602715870fc496cca4b81e16274c7696e53114b8d8fc4745

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
html2rss-0.15.0 lib/html2rss/rss_builder/stylesheet.rb
html2rss-0.14.0 lib/html2rss/rss_builder/stylesheet.rb