lib/css_parser.rb in css_parser-1.3.1 vs lib/css_parser.rb in css_parser-1.3.2
- old
+ new
@@ -5,14 +5,18 @@
require 'digest/md5'
require 'zlib'
require 'stringio'
require 'iconv' unless String.method_defined?(:encode)
+require 'css_parser/rule_set'
+require 'css_parser/regexps'
+require 'css_parser/parser'
+
module CssParser
- VERSION = '1.2.6'
+ autoload :VERSION, "css_parser/version"
- # Merge multiple CSS RuleSets by cascading according to the CSS 2.1 cascading rules
+ # Merge multiple CSS RuleSets by cascading according to the CSS 2.1 cascading rules
# (http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order).
#
# Takes one or more RuleSet objects.
#
# Returns a RuleSet.
@@ -46,11 +50,11 @@
# puts merged
# => "{ background: none black; }"
#--
# TODO: declaration_hashes should be able to contain a RuleSet
# this should be a Class method
- def CssParser.merge(*rule_sets)
+ def self.merge(*rule_sets)
@folded_declaration_cache = {}
# in case called like CssParser.merge([rule_set, rule_set])
rule_sets.flatten! if rule_sets[0].kind_of?(Array)
@@ -114,11 +118,11 @@
# CssParser.calculate_specificity('#content div p:first-line a:link')
# => 114
#--
# Thanks to Rafael Salazar and Nick Fitzsimons on the css-discuss list for their help.
#++
- def CssParser.calculate_specificity(selector)
+ def self.calculate_specificity(selector)
a = 0
b = selector.scan(/\#/).length
c = selector.scan(NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX).length
d = selector.scan(ELEMENTS_AND_PSEUDO_ELEMENTS_RX).length
@@ -160,9 +164,5 @@
mq = raw.to_s.gsub(/[\s]+/, ' ').strip
mq = 'all' if mq.empty?
mq.to_sym
end
end
-
-require File.dirname(__FILE__) + '/css_parser/rule_set'
-require File.dirname(__FILE__) + '/css_parser/regexps'
-require File.dirname(__FILE__) + '/css_parser/parser'