Sha256: a7212d38d3585890a60e99faf38803ae891ad8d0d5cb7175c2f7535a784ec9f4

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

require "unused_css/version"
require "unused_css/stylesheet"

module UnusedCSS
  class Watcher
    attr_accessor :stylesheets

    def initialize
      @stylesheets = Stylesheets.new
    end

    def watch!(watir_browser)
      unused_css_block = Proc.new do |unused_css|
        @unused_css = unused_css
        def goto(uri)
          super(uri)
          stylesheets = elements(tag_name: 'link').map {|stylesheet| stylesheet.attribute_value('href') }
          @unused_css.stylesheets.add stylesheets
          stylesheets.each do |stylesheet|
            stylesheet = @unused_css.stylesheets[stylesheet]
            stylesheet.styles.delete_if {|style| self.element(css: style).exist? }
            stylesheet.remove_pseudo_styles!
          end
        end
      end
      watir_browser.instance_exec self, &unused_css_block
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unused_css-0.0.1 lib/unused_css.rb