Sha256: a2642c747c6e0b6916bdbdd0dd9fc0683d9e6e78cdfac913c37d2f19978b00c0
Contents?: true
Size: 1001 Bytes
Versions: 2
Compression:
Stored size: 1001 Bytes
Contents
require "css_parser" class Stylesheet attr_accessor :uri, :styles, :parser def initialize (uri) @styles = Set.new @uri = uri parse_styles! end def parse_styles! @parser = CssParser::Parser.new @parser.load_uri! @uri @parser.each_selector { |styles| @styles << styles } end def remove_pseudo_styles! @styles.delete_if { |style| style.match /::?[\w\-]+/ } end end class Stylesheets include Enumerable attr_accessor :stylesheets def initialize @stylesheets = [] end def add uris uris = Array(uris) uris.each { |uri| @stylesheets << Stylesheet.new(uri) unless already_included? uri } end def already_included? uri @stylesheets.any? { |stylesheet| stylesheet.uri == uri } end def [](uri) @stylesheets.find { |stylesheet| stylesheet.uri == uri } end def each &block @stylesheets.each &block end def styles @stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.styles } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unused_css-0.2.0 | lib/unused_css/stylesheet.rb |
unused_css-0.1.0 | lib/unused_css/stylesheet.rb |