Sha256: a5bc584645ed5be54dc7abfc4ac122e17b4d366e04497776602ee8a222901196

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

require "unused_css/stylesheet"

module Watir

  class Browser
    attr_accessor :stylesheets

    alias_method :original_initialize, :initialize
    def initialize(*args)
      @stylesheets = Stylesheets.new
      original_initialize(*args)
    end

    alias_method :original_goto, :goto
    def goto(*args)
      original_goto(*args)
      @stylesheets.add stylesheets_on_page
      check_for_unused_styles!
    end

    def stylesheets_on_page
      elements(tag_name: 'link').map { |stylesheet| stylesheet.attribute_value('href') }
    end

    def check_for_unused_styles!
      @stylesheets.each do |stylesheet|
        stylesheet.unused_styles.delete_if { |style| self.element(css: style).exist? }
        stylesheet.remove_pseudo_styles!
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unused_css-1.0.0 lib/unused_css/watir.rb