Sha256: 41bf5dc88ad222d687faa87a171b10bb222d7bdf3746a3643410ce0acf40e355

Contents?: true

Size: 613 Bytes

Versions: 1

Compression:

Stored size: 613 Bytes

Contents

class PageDownloader
  class Filters
    class EmbedStyle < EmbedScript
      def filter(content)
        content.css("link").select do |link|
          stylesheet?(link)
        end.each do |link|
          embed(link)
        end

        content
      end

      private

      def stylesheet?(link)
        rel = link.attributes["rel"]
        rel && rel.value.downcase == "stylesheet"
      end

      def embed(link)
        content = fetch_content(link.attributes["href"].value)
        html = "<style>#{content}</style>"
        link.parent.add_child(html)
        link.remove
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
page_downloader-1.0 lib/page_downloader/filters/embed_style.rb