Sha256: 22263cdec9c4b04e471c2cc8bdf587d790acacd9b95d2752bcfe96f3496386c5

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

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

        def check_for_unused_styles!
          @unused_css.stylesheets.each do |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.1.0 lib/unused_css.rb