lib/css_parser.rb in css_parser-1.3.2 vs lib/css_parser.rb in css_parser-1.3.3
- old
+ new
@@ -5,29 +5,29 @@
require 'digest/md5'
require 'zlib'
require 'stringio'
require 'iconv' unless String.method_defined?(:encode)
+require 'css_parser/version'
require 'css_parser/rule_set'
require 'css_parser/regexps'
require 'css_parser/parser'
module CssParser
- autoload :VERSION, "css_parser/version"
# 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.
#
# ==== Cascading
- # If a RuleSet object has its +specificity+ defined, that specificity is
- # used in the cascade calculations.
+ # If a RuleSet object has its +specificity+ defined, that specificity is
+ # used in the cascade calculations.
#
- # If no specificity is explicitly set and the RuleSet has *one* selector,
+ # If no specificity is explicitly set and the RuleSet has *one* selector,
# the specificity is calculated using that selector.
#
# If no selectors the specificity is treated as 0.
#
# If multiple selectors are present then the greatest specificity is used.
@@ -55,11 +55,11 @@
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)
-
+
unless rule_sets.all? {|rs| rs.kind_of?(CssParser::RuleSet)}
raise ArgumentError, "all parameters must be CssParser::RuleSets."
end
return rule_sets[0] if rule_sets.length == 1
@@ -67,11 +67,11 @@
# Internal storage of CSS properties that we will keep
properties = {}
rule_sets.each do |rule_set|
rule_set.expand_shorthand!
-
+
specificity = rule_set.specificity
unless specificity
if rule_set.selectors.length == 0
specificity = 0
else
@@ -83,25 +83,25 @@
# Add the property to the list to be folded per http://www.w3.org/TR/CSS21/cascade.html#cascading-order
if not properties.has_key?(property)
properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
elsif is_important
if not properties[property][:is_important] or properties[property][:specificity] <= specificity
- properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
+ properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
end
elsif properties[property][:specificity] < specificity or properties[property][:specificity] == specificity
unless properties[property][:is_important]
- properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
+ properties[property] = {:value => value, :specificity => specificity, :is_important => is_important}
end
end
end
end
merged = RuleSet.new(nil, nil)
properties.each do |property, details|
if details[:is_important]
- merged[property.strip] = details[:value].strip.gsub(/\;\Z/, '') + '!important'
+ merged[property.strip] = details[:value].strip.gsub(/\;\Z/, '') + '!important'
else
merged[property.strip] = details[:value].strip
end
end
@@ -139,11 +139,11 @@
# per http://www.w3.org/TR/CSS21/syndata.html#uri
#
# Returns a string.
#
# ==== Example
- # CssParser.convert_uris("body { background: url('../style/yellow.png?abc=123') };",
+ # CssParser.convert_uris("body { background: url('../style/yellow.png?abc=123') };",
# "http://example.org/style/basic.css").inspect
# => "body { background: url('http://example.org/style/yellow.png?abc=123') };"
def self.convert_uris(css, base_uri)
base_uri = Addressable::URI.parse(base_uri) unless base_uri.kind_of?(Addressable::URI)
@@ -157,10 +157,10 @@
rescue; end
end
"url('#{uri.to_s}')"
end
end
-
+
def self.sanitize_media_query(raw)
mq = raw.to_s.gsub(/[\s]+/, ' ').strip
mq = 'all' if mq.empty?
mq.to_sym
end