Sha256: 51db7e7b9aa416a172e534ef0f9e0eb27276f41449e97f5fc16bdcefcdb669d6

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 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
  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 styles
    @stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.styles }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unused_css-0.0.1 lib/unused_css/stylesheet.rb