From f8857357e85aafddf60a421dd17bf907e157d7d7 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Mon, 18 Jan 2010 18:52:55 -0500 Subject: [PATCH] Update css_parser --- vendor/gems/css_parser-0.9.1/CHANGELOG | 13 ----- vendor/gems/css_parser-0.9.1/LICENSE | 21 ------- vendor/gems/css_parser-0.9.1/README | 58 ------------------- .../lib/css_parser.rb | 2 +- .../lib/css_parser/parser.rb | 2 +- .../lib/css_parser/regexps.rb | 8 +-- .../lib/css_parser/rule_set.rb | 19 +++--- .../fixtures/import-circular-reference.css | 0 .../test/fixtures/import-with-media-types.css | 0 .../test/fixtures/import1.css | 0 .../test/fixtures/simple.css | 0 .../test/fixtures/subdir/import2.css | 0 .../test/test_css_parser_basic.rb | 0 .../test/test_css_parser_downloading.rb | 0 .../test/test_css_parser_media_types.rb | 0 .../test/test_css_parser_misc.rb | 0 .../test/test_css_parser_regexps.rb | 1 + .../test/test_helper.rb | 16 ++--- .../test/test_merging.rb | 0 .../test/test_rule_set.rb | 9 +-- .../test/test_rule_set_creating_shorthand.rb | 0 .../test/test_rule_set_expanding_shorthand.rb | 0 22 files changed, 31 insertions(+), 118 deletions(-) delete mode 100644 vendor/gems/css_parser-0.9.1/CHANGELOG delete mode 100644 vendor/gems/css_parser-0.9.1/LICENSE delete mode 100644 vendor/gems/css_parser-0.9.1/README rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/lib/css_parser.rb (99%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/lib/css_parser/parser.rb (99%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/lib/css_parser/regexps.rb (93%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/lib/css_parser/rule_set.rb (97%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/fixtures/import-circular-reference.css (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/fixtures/import-with-media-types.css (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/fixtures/import1.css (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/fixtures/simple.css (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/fixtures/subdir/import2.css (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_css_parser_basic.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_css_parser_downloading.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_css_parser_media_types.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_css_parser_misc.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_css_parser_regexps.rb (99%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_helper.rb (96%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_merging.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_rule_set.rb (96%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_rule_set_creating_shorthand.rb (100%) rename vendor/gems/{css_parser-0.9.1 => css_parser-1.0.0}/test/test_rule_set_expanding_shorthand.rb (100%) diff --git a/vendor/gems/css_parser-0.9.1/CHANGELOG b/vendor/gems/css_parser-0.9.1/CHANGELOG deleted file mode 100644 index 4f6047c..0000000 --- a/vendor/gems/css_parser-0.9.1/CHANGELOG +++ /dev/null @@ -1,13 +0,0 @@ -=== Ruby CSS Parser CHANGELOG - -==== Version 0.9.1 - * Fixed RuleSet#declaration_to_s so it would respect !important - rules (thanks to Dana - http://github.com/DanaDanger) - -==== Version 0.9 - * Initial version forked from Premailer project - -==== TODO: Future - * border shorthand/folding support - * re-implement caching on CssParser.merge - * correctly parse http://www.webstandards.org/files/acid2/test.html \ No newline at end of file diff --git a/vendor/gems/css_parser-0.9.1/LICENSE b/vendor/gems/css_parser-0.9.1/LICENSE deleted file mode 100644 index afa96fa..0000000 --- a/vendor/gems/css_parser-0.9.1/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -=== Ruby CSS Parser License - -Copyright (c) 2007 Alex Dunae - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/vendor/gems/css_parser-0.9.1/README b/vendor/gems/css_parser-0.9.1/README deleted file mode 100644 index 741eeab..0000000 --- a/vendor/gems/css_parser-0.9.1/README +++ /dev/null @@ -1,58 +0,0 @@ -=== Ruby CSS Parser - -Load, parse and cascade CSS rule sets in Ruby. - -==== Setup - -Install the gem from RubyGems. - - gem install css_parser - -Done. - -==== An example - require 'css_parser' - include CssParser - - parser = CssParser::Parser.new - parser.load_file!('http://example.com/styles/style.css') - - # lookup a rule by a selector - parser.find('#content') - #=> 'font-size: 13px; line-height: 1.2;' - - # lookup a rule by a selector and media type - parser.find('#content', [:screen, :handheld]) - - # iterate through selectors by media type - parser.each_selector(:screen) do |selector, declarations, specificity| - ... - end - - # add a block of CSS - css = <<-EOT - body { margin: 0 1em; } - EOT - - parser.add_block!(css) - - # output all CSS rules in a single stylesheet - parser.to_s - => #content { font-size: 13px; line-height: 1.2; } - body { margin: 0 1em; } - -==== Testing - -You can run the suite of unit tests using rake test. - -The download/import tests require that WEBrick is installed. The tests set up -a temporary server on port 12000 and pull down files from the test/fixtures/ -directory. - -==== Credits and code - -By Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-08. - -Thanks to Dana (http://github.com/DanaDanger) for the 0.9.1 update. - -Made on Vancouver Island. \ No newline at end of file diff --git a/vendor/gems/css_parser-0.9.1/lib/css_parser.rb b/vendor/gems/css_parser-1.0.0/lib/css_parser.rb similarity index 99% rename from vendor/gems/css_parser-0.9.1/lib/css_parser.rb rename to vendor/gems/css_parser-1.0.0/lib/css_parser.rb index bed9ebb..1955e68 100644 --- a/vendor/gems/css_parser-0.9.1/lib/css_parser.rb +++ b/vendor/gems/css_parser-1.0.0/lib/css_parser.rb @@ -1,6 +1,6 @@ $:.unshift File.dirname(__FILE__) require 'uri' -require 'md5' +require 'digest/md5' require 'zlib' require 'iconv' require 'css_parser/rule_set' diff --git a/vendor/gems/css_parser-0.9.1/lib/css_parser/parser.rb b/vendor/gems/css_parser-1.0.0/lib/css_parser/parser.rb similarity index 99% rename from vendor/gems/css_parser-0.9.1/lib/css_parser/parser.rb rename to vendor/gems/css_parser-1.0.0/lib/css_parser/parser.rb index c54a0dc..02df62d 100644 --- a/vendor/gems/css_parser-0.9.1/lib/css_parser/parser.rb +++ b/vendor/gems/css_parser-1.0.0/lib/css_parser/parser.rb @@ -15,7 +15,7 @@ class CircularReferenceError < StandardError; end # [import] Follow @import rules. Boolean, default is true. # [io_exceptions] Throw an exception if a link can not be found. Boolean, default is true. class Parser - USER_AGENT = "Ruby CSS Parser/#{VERSION} (http://code.dunae.ca/css_parser/)" + USER_AGENT = "Ruby CSS Parser/#{RUBY_VERSION} (http://code.dunae.ca/css_parser/)" STRIP_CSS_COMMENTS_RX = /\/\*.*?\*\//m STRIP_HTML_COMMENTS_RX = /\<\!\-\-|\-\-\>/m diff --git a/vendor/gems/css_parser-0.9.1/lib/css_parser/regexps.rb b/vendor/gems/css_parser-1.0.0/lib/css_parser/regexps.rb similarity index 93% rename from vendor/gems/css_parser-0.9.1/lib/css_parser/regexps.rb rename to vendor/gems/css_parser-1.0.0/lib/css_parser/regexps.rb index 2abedef..dcca7d5 100644 --- a/vendor/gems/css_parser-0.9.1/lib/css_parser/regexps.rb +++ b/vendor/gems/css_parser-1.0.0/lib/css_parser/regexps.rb @@ -2,17 +2,17 @@ module CssParser # :stopdoc: # Base types RE_NL = Regexp.new('(\n|\r\n|\r|\f)') - RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE) #[^\0-\177] - RE_UNICODE = Regexp.new('(\\\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])*)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE) + RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE, 'n') #[^\0-\177] + RE_UNICODE = Regexp.new('(\\\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])*)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE, 'n') RE_ESCAPE = Regexp.union(RE_UNICODE, '|(\\\\[^\n\r\f0-9a-f])') - RE_IDENT = Regexp.new("[\-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9\-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE) + RE_IDENT = Regexp.new("[\-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9\-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE, 'n') # General strings RE_STRING1 = Regexp.new('(\"(.[^\n\r\f\\"]*|\\\\' + RE_NL.to_s + '|' + RE_ESCAPE.to_s + ')*\")') RE_STRING2 = Regexp.new('(\'(.[^\n\r\f\\\']*|\\\\' + RE_NL.to_s + '|' + RE_ESCAPE.to_s + ')*\')') RE_STRING = Regexp.union(RE_STRING1, RE_STRING2) - RE_URI = Regexp.new('(url\([\s]*([\s]*' + RE_STRING.to_s + '[\s]*)[\s]*\))|(url\([\s]*([!#$%&*\-~]|' + RE_NON_ASCII.to_s + '|' + RE_ESCAPE.to_s + ')*[\s]*)\)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE) + RE_URI = Regexp.new('(url\([\s]*([\s]*' + RE_STRING.to_s + '[\s]*)[\s]*\))|(url\([\s]*([!#$%&*\-~]|' + RE_NON_ASCII.to_s + '|' + RE_ESCAPE.to_s + ')*[\s]*)\)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE, 'n') URI_RX = /url\(("([^"]*)"|'([^']*)'|([^)]*))\)/im # Initial parsing diff --git a/vendor/gems/css_parser-0.9.1/lib/css_parser/rule_set.rb b/vendor/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb similarity index 97% rename from vendor/gems/css_parser-0.9.1/lib/css_parser/rule_set.rb rename to vendor/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb index 3a47170..ae3e0eb 100644 --- a/vendor/gems/css_parser-0.9.1/lib/css_parser/rule_set.rb +++ b/vendor/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb @@ -48,6 +48,11 @@ def get_value(property) # # If the property already exists its value will be over-written. def add_declaration!(property, value) + if value.nil? or value.empty? + @declarations.delete(property) + return + end + value.gsub!(/;\Z/, '') is_important = !value.gsub!(CssParser::IMPORTANT_IN_PROPERTY_RX, '').nil? property = property.downcase.strip @@ -84,13 +89,14 @@ def each_declaration # :yields: property, value, is_important end # Return all declarations as a string. + #-- + # TODO: Clean-up regexp doesn't seem to work + #++ def declarations_to_s(options = {}) options = {:force_important => false}.merge(options) str = '' - each_declaration do |prop, val, is_important| - importance = (options[:force_important] || is_important) ? ' !important' : '' - str += "#{prop}: #{val}#{importance}; " - end + importance = options[:force_important] ? ' !important' : '' + each_declaration { |prop, val| str += "#{prop}: #{val}#{importance}; " } str.gsub(/^[\s]+|[\n\r\f\t]*|[\s]+$/mx, '').strip end @@ -138,6 +144,7 @@ def parse_selectors!(selectors) # :nodoc: @selectors = selectors.split(',') end +public # Split shorthand dimensional declarations (e.g. margin: 0px auto;) # into their constituent parts. def expand_dimensions_shorthand! # :nodoc: @@ -372,9 +379,5 @@ def create_font_shorthand! # :nodoc: end end - - - - end end \ No newline at end of file diff --git a/vendor/gems/css_parser-0.9.1/test/fixtures/import-circular-reference.css b/vendor/gems/css_parser-1.0.0/test/fixtures/import-circular-reference.css similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/fixtures/import-circular-reference.css rename to vendor/gems/css_parser-1.0.0/test/fixtures/import-circular-reference.css diff --git a/vendor/gems/css_parser-0.9.1/test/fixtures/import-with-media-types.css b/vendor/gems/css_parser-1.0.0/test/fixtures/import-with-media-types.css similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/fixtures/import-with-media-types.css rename to vendor/gems/css_parser-1.0.0/test/fixtures/import-with-media-types.css diff --git a/vendor/gems/css_parser-0.9.1/test/fixtures/import1.css b/vendor/gems/css_parser-1.0.0/test/fixtures/import1.css similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/fixtures/import1.css rename to vendor/gems/css_parser-1.0.0/test/fixtures/import1.css diff --git a/vendor/gems/css_parser-0.9.1/test/fixtures/simple.css b/vendor/gems/css_parser-1.0.0/test/fixtures/simple.css similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/fixtures/simple.css rename to vendor/gems/css_parser-1.0.0/test/fixtures/simple.css diff --git a/vendor/gems/css_parser-0.9.1/test/fixtures/subdir/import2.css b/vendor/gems/css_parser-1.0.0/test/fixtures/subdir/import2.css similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/fixtures/subdir/import2.css rename to vendor/gems/css_parser-1.0.0/test/fixtures/subdir/import2.css diff --git a/vendor/gems/css_parser-0.9.1/test/test_css_parser_basic.rb b/vendor/gems/css_parser-1.0.0/test/test_css_parser_basic.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_css_parser_basic.rb rename to vendor/gems/css_parser-1.0.0/test/test_css_parser_basic.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_css_parser_downloading.rb b/vendor/gems/css_parser-1.0.0/test/test_css_parser_downloading.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_css_parser_downloading.rb rename to vendor/gems/css_parser-1.0.0/test/test_css_parser_downloading.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_css_parser_media_types.rb b/vendor/gems/css_parser-1.0.0/test/test_css_parser_media_types.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_css_parser_media_types.rb rename to vendor/gems/css_parser-1.0.0/test/test_css_parser_media_types.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_css_parser_misc.rb b/vendor/gems/css_parser-1.0.0/test/test_css_parser_misc.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_css_parser_misc.rb rename to vendor/gems/css_parser-1.0.0/test/test_css_parser_misc.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_css_parser_regexps.rb b/vendor/gems/css_parser-1.0.0/test/test_css_parser_regexps.rb similarity index 99% rename from vendor/gems/css_parser-0.9.1/test/test_css_parser_regexps.rb rename to vendor/gems/css_parser-1.0.0/test/test_css_parser_regexps.rb index 7122429..6605a8a 100644 --- a/vendor/gems/css_parser-0.9.1/test/test_css_parser_regexps.rb +++ b/vendor/gems/css_parser-1.0.0/test/test_css_parser_regexps.rb @@ -1,3 +1,4 @@ +# coding: iso-8859-1 require File.dirname(__FILE__) + '/test_helper' # Test cases for CSS regular expressions diff --git a/vendor/gems/css_parser-0.9.1/test/test_helper.rb b/vendor/gems/css_parser-1.0.0/test/test_helper.rb similarity index 96% rename from vendor/gems/css_parser-0.9.1/test/test_helper.rb rename to vendor/gems/css_parser-1.0.0/test/test_helper.rb index 84f9e45..4c74ae1 100644 --- a/vendor/gems/css_parser-0.9.1/test/test_helper.rb +++ b/vendor/gems/css_parser-1.0.0/test/test_helper.rb @@ -1,8 +1,8 @@ -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../')) -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/')) -require 'rubygems' -require 'test/unit' -require 'css_parser' -require 'net/http' -require 'open-uri' -require 'WEBrick' +$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../')) +$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/')) +require 'rubygems' +require 'test/unit' +require 'css_parser' +require 'net/http' +require 'open-uri' +require 'WEBrick' diff --git a/vendor/gems/css_parser-0.9.1/test/test_merging.rb b/vendor/gems/css_parser-1.0.0/test/test_merging.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_merging.rb rename to vendor/gems/css_parser-1.0.0/test/test_merging.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_rule_set.rb b/vendor/gems/css_parser-1.0.0/test/test_rule_set.rb similarity index 96% rename from vendor/gems/css_parser-0.9.1/test/test_rule_set.rb rename to vendor/gems/css_parser-1.0.0/test/test_rule_set.rb index ac3236a..d963894 100644 --- a/vendor/gems/css_parser-0.9.1/test/test_rule_set.rb +++ b/vendor/gems/css_parser-1.0.0/test/test_rule_set.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/test_helper' +require "set" # Test cases for parsing CSS blocks class RuleSetTests < Test::Unit::TestCase @@ -32,7 +33,7 @@ def test_each_selector expected = [ {:selector => "#content p", :declarations => "color: #fff;", :specificity => 101}, {:selector => "a", :declarations => "color: #fff;", :specificity => 1} - ] + ] actual = [] rs = RuleSet.new('#content p, a', 'color: #fff;') @@ -44,13 +45,13 @@ def test_each_selector end def test_each_declaration - expected = [ + expected = Set.new([ {:property => 'margin', :value => '1px -0.25em', :is_important => false}, {:property => 'background', :value => 'white none no-repeat', :is_important => true}, {:property => 'color', :value => '#fff', :is_important => false} - ] + ]) - actual = [] + actual = Set.new rs = RuleSet.new(nil, 'color: #fff; Background: white none no-repeat !important; margin: 1px -0.25em;') rs.each_declaration do |prop, val, imp| actual << {:property => prop, :value => val, :is_important => imp} diff --git a/vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb b/vendor/gems/css_parser-1.0.0/test/test_rule_set_creating_shorthand.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb rename to vendor/gems/css_parser-1.0.0/test/test_rule_set_creating_shorthand.rb diff --git a/vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb b/vendor/gems/css_parser-1.0.0/test/test_rule_set_expanding_shorthand.rb similarity index 100% rename from vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb rename to vendor/gems/css_parser-1.0.0/test/test_rule_set_expanding_shorthand.rb