deadweight 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/deadweight.gemspec +21 -24
- data/lib/deadweight.rb +25 -20
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/lib/css_parser.rb +1 -1
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/lib/css_parser/parser.rb +1 -1
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/lib/css_parser/regexps.rb +4 -4
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/lib/css_parser/rule_set.rb +11 -8
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/import-circular-reference.css +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/import-with-media-types.css +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/import1.css +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/simple.css +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/subdir/import2.css +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_css_parser_basic.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_css_parser_downloading.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_css_parser_media_types.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_css_parser_misc.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_css_parser_regexps.rb +1 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_helper.rb +8 -8
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_merging.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_rule_set.rb +5 -4
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_rule_set_creating_shorthand.rb +0 -0
- data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_rule_set_expanding_shorthand.rb +0 -0
- metadata +21 -24
- data/vendor/gems/css_parser-0.9.1/CHANGELOG +0 -13
- data/vendor/gems/css_parser-0.9.1/LICENSE +0 -21
- data/vendor/gems/css_parser-0.9.1/README +0 -58
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/deadweight.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{deadweight}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aanand Prasad"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-18}
|
13
13
|
s.default_executable = %q{deadweight}
|
14
14
|
s.email = %q{aanand.prasad@gmail.com}
|
15
15
|
s.executables = ["deadweight"]
|
@@ -36,28 +36,25 @@ Gem::Specification.new do |s|
|
|
36
36
|
"test/fixtures/style.css",
|
37
37
|
"test/rake_task_test.rb",
|
38
38
|
"test/test_helper.rb",
|
39
|
-
"vendor/gems/css_parser-0.
|
40
|
-
"vendor/gems/css_parser-0.
|
41
|
-
"vendor/gems/css_parser-0.
|
42
|
-
"vendor/gems/css_parser-0.
|
43
|
-
"vendor/gems/css_parser-0.
|
44
|
-
"vendor/gems/css_parser-0.
|
45
|
-
"vendor/gems/css_parser-0.
|
46
|
-
"vendor/gems/css_parser-0.
|
47
|
-
"vendor/gems/css_parser-0.
|
48
|
-
"vendor/gems/css_parser-0.
|
49
|
-
"vendor/gems/css_parser-0.
|
50
|
-
"vendor/gems/css_parser-0.
|
51
|
-
"vendor/gems/css_parser-0.
|
52
|
-
"vendor/gems/css_parser-0.
|
53
|
-
"vendor/gems/css_parser-0.
|
54
|
-
"vendor/gems/css_parser-0.
|
55
|
-
"vendor/gems/css_parser-0.
|
56
|
-
"vendor/gems/css_parser-0.
|
57
|
-
"vendor/gems/css_parser-0.
|
58
|
-
"vendor/gems/css_parser-0.9.1/test/test_rule_set.rb",
|
59
|
-
"vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb",
|
60
|
-
"vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb"
|
39
|
+
"vendor/gems/css_parser-1.0.0/lib/css_parser.rb",
|
40
|
+
"vendor/gems/css_parser-1.0.0/lib/css_parser/parser.rb",
|
41
|
+
"vendor/gems/css_parser-1.0.0/lib/css_parser/regexps.rb",
|
42
|
+
"vendor/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb",
|
43
|
+
"vendor/gems/css_parser-1.0.0/test/fixtures/import-circular-reference.css",
|
44
|
+
"vendor/gems/css_parser-1.0.0/test/fixtures/import-with-media-types.css",
|
45
|
+
"vendor/gems/css_parser-1.0.0/test/fixtures/import1.css",
|
46
|
+
"vendor/gems/css_parser-1.0.0/test/fixtures/simple.css",
|
47
|
+
"vendor/gems/css_parser-1.0.0/test/fixtures/subdir/import2.css",
|
48
|
+
"vendor/gems/css_parser-1.0.0/test/test_css_parser_basic.rb",
|
49
|
+
"vendor/gems/css_parser-1.0.0/test/test_css_parser_downloading.rb",
|
50
|
+
"vendor/gems/css_parser-1.0.0/test/test_css_parser_media_types.rb",
|
51
|
+
"vendor/gems/css_parser-1.0.0/test/test_css_parser_misc.rb",
|
52
|
+
"vendor/gems/css_parser-1.0.0/test/test_css_parser_regexps.rb",
|
53
|
+
"vendor/gems/css_parser-1.0.0/test/test_helper.rb",
|
54
|
+
"vendor/gems/css_parser-1.0.0/test/test_merging.rb",
|
55
|
+
"vendor/gems/css_parser-1.0.0/test/test_rule_set.rb",
|
56
|
+
"vendor/gems/css_parser-1.0.0/test/test_rule_set_creating_shorthand.rb",
|
57
|
+
"vendor/gems/css_parser-1.0.0/test/test_rule_set_expanding_shorthand.rb"
|
61
58
|
]
|
62
59
|
s.homepage = %q{http://github.com/aanand/deadweight}
|
63
60
|
s.rdoc_options = ["--charset=UTF-8"]
|
data/lib/deadweight.rb
CHANGED
@@ -42,35 +42,40 @@ class Deadweight
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
css
|
45
|
+
def add_css!(css)
|
46
|
+
parser = CssParser::Parser.new
|
47
|
+
parser.add_block!(css)
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
selector_count = 0
|
50
|
+
|
51
|
+
parser.each_selector do |selector, declarations, specificity|
|
52
|
+
next if @unused_selectors.include?(selector)
|
53
|
+
next if selector =~ @ignore_selectors
|
54
|
+
next if has_pseudo_classes(selector) and @unused_selectors.include?(strip(selector))
|
55
|
+
|
56
|
+
@unused_selectors << selector
|
57
|
+
@parsed_rules[selector] = declarations
|
58
|
+
|
59
|
+
selector_count += 1
|
51
60
|
end
|
52
61
|
|
53
|
-
|
62
|
+
selector_count
|
63
|
+
end
|
54
64
|
|
65
|
+
# Find all unused CSS selectors and return them as an array.
|
66
|
+
def run
|
55
67
|
@parsed_rules = {}
|
56
68
|
@unused_selectors = []
|
57
69
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@unused_selectors << selector
|
62
|
-
@parsed_rules[selector] = declarations
|
63
|
-
end
|
64
|
-
end
|
70
|
+
@stylesheets.each do |path|
|
71
|
+
new_selector_count = add_css!(fetch(path))
|
72
|
+
log.puts(" found #{new_selector_count} selectors".yellow)
|
65
73
|
end
|
66
74
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if has_pseudo_classes(selector) && @unused_selectors.include?(strip(selector))
|
72
|
-
@unused_selectors.delete(selector)
|
73
|
-
end
|
75
|
+
if @rules and !@rules.empty?
|
76
|
+
new_selector_count = add_css!(@rules)
|
77
|
+
log.puts
|
78
|
+
log.puts("Added #{new_selector_count} extra selectors".yellow)
|
74
79
|
end
|
75
80
|
|
76
81
|
total_selectors = @unused_selectors.size
|
@@ -15,7 +15,7 @@ module CssParser
|
|
15
15
|
# [<tt>import</tt>] Follow <tt>@import</tt> rules. Boolean, default is <tt>true</tt>.
|
16
16
|
# [<tt>io_exceptions</tt>] Throw an exception if a link can not be found. Boolean, default is <tt>true</tt>.
|
17
17
|
class Parser
|
18
|
-
USER_AGENT = "Ruby CSS Parser/#{
|
18
|
+
USER_AGENT = "Ruby CSS Parser/#{RUBY_VERSION} (http://code.dunae.ca/css_parser/)"
|
19
19
|
|
20
20
|
STRIP_CSS_COMMENTS_RX = /\/\*.*?\*\//m
|
21
21
|
STRIP_HTML_COMMENTS_RX = /\<\!\-\-|\-\-\>/m
|
@@ -2,17 +2,17 @@ module CssParser
|
|
2
2
|
# :stopdoc:
|
3
3
|
# Base types
|
4
4
|
RE_NL = Regexp.new('(\n|\r\n|\r|\f)')
|
5
|
-
RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE) #[^\0-\177]
|
6
|
-
RE_UNICODE = Regexp.new('(\\\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])*)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE)
|
5
|
+
RE_NON_ASCII = Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE, 'n') #[^\0-\177]
|
6
|
+
RE_UNICODE = Regexp.new('(\\\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])*)', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE, 'n')
|
7
7
|
RE_ESCAPE = Regexp.union(RE_UNICODE, '|(\\\\[^\n\r\f0-9a-f])')
|
8
|
-
RE_IDENT = Regexp.new("[\-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9\-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE)
|
8
|
+
RE_IDENT = Regexp.new("[\-]?([_a-z]|#{RE_NON_ASCII}|#{RE_ESCAPE})([_a-z0-9\-]|#{RE_NON_ASCII}|#{RE_ESCAPE})*", Regexp::IGNORECASE, 'n')
|
9
9
|
|
10
10
|
# General strings
|
11
11
|
RE_STRING1 = Regexp.new('(\"(.[^\n\r\f\\"]*|\\\\' + RE_NL.to_s + '|' + RE_ESCAPE.to_s + ')*\")')
|
12
12
|
RE_STRING2 = Regexp.new('(\'(.[^\n\r\f\\\']*|\\\\' + RE_NL.to_s + '|' + RE_ESCAPE.to_s + ')*\')')
|
13
13
|
RE_STRING = Regexp.union(RE_STRING1, RE_STRING2)
|
14
14
|
|
15
|
-
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)
|
15
|
+
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')
|
16
16
|
URI_RX = /url\(("([^"]*)"|'([^']*)'|([^)]*))\)/im
|
17
17
|
|
18
18
|
# Initial parsing
|
@@ -48,6 +48,11 @@ module CssParser
|
|
48
48
|
#
|
49
49
|
# If the property already exists its value will be over-written.
|
50
50
|
def add_declaration!(property, value)
|
51
|
+
if value.nil? or value.empty?
|
52
|
+
@declarations.delete(property)
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
51
56
|
value.gsub!(/;\Z/, '')
|
52
57
|
is_important = !value.gsub!(CssParser::IMPORTANT_IN_PROPERTY_RX, '').nil?
|
53
58
|
property = property.downcase.strip
|
@@ -84,13 +89,14 @@ module CssParser
|
|
84
89
|
end
|
85
90
|
|
86
91
|
# Return all declarations as a string.
|
92
|
+
#--
|
93
|
+
# TODO: Clean-up regexp doesn't seem to work
|
94
|
+
#++
|
87
95
|
def declarations_to_s(options = {})
|
88
96
|
options = {:force_important => false}.merge(options)
|
89
97
|
str = ''
|
90
|
-
|
91
|
-
|
92
|
-
str += "#{prop}: #{val}#{importance}; "
|
93
|
-
end
|
98
|
+
importance = options[:force_important] ? ' !important' : ''
|
99
|
+
each_declaration { |prop, val| str += "#{prop}: #{val}#{importance}; " }
|
94
100
|
str.gsub(/^[\s]+|[\n\r\f\t]*|[\s]+$/mx, '').strip
|
95
101
|
end
|
96
102
|
|
@@ -138,6 +144,7 @@ private
|
|
138
144
|
@selectors = selectors.split(',')
|
139
145
|
end
|
140
146
|
|
147
|
+
public
|
141
148
|
# Split shorthand dimensional declarations (e.g. <tt>margin: 0px auto;</tt>)
|
142
149
|
# into their constituent parts.
|
143
150
|
def expand_dimensions_shorthand! # :nodoc:
|
@@ -372,9 +379,5 @@ private
|
|
372
379
|
end
|
373
380
|
|
374
381
|
end
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
382
|
end
|
380
383
|
end
|
data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/import-circular-reference.css
RENAMED
File without changes
|
data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/fixtures/import-with-media-types.css
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,8 +1,8 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../'))
|
2
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/'))
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'css_parser'
|
6
|
-
require 'net/http'
|
7
|
-
require 'open-uri'
|
8
|
-
require 'WEBrick'
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../'))
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../lib/'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'css_parser'
|
6
|
+
require 'net/http'
|
7
|
+
require 'open-uri'
|
8
|
+
require 'WEBrick'
|
File without changes
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require "set"
|
2
3
|
|
3
4
|
# Test cases for parsing CSS blocks
|
4
5
|
class RuleSetTests < Test::Unit::TestCase
|
@@ -32,7 +33,7 @@ class RuleSetTests < Test::Unit::TestCase
|
|
32
33
|
expected = [
|
33
34
|
{:selector => "#content p", :declarations => "color: #fff;", :specificity => 101},
|
34
35
|
{:selector => "a", :declarations => "color: #fff;", :specificity => 1}
|
35
|
-
]
|
36
|
+
]
|
36
37
|
|
37
38
|
actual = []
|
38
39
|
rs = RuleSet.new('#content p, a', 'color: #fff;')
|
@@ -44,13 +45,13 @@ class RuleSetTests < Test::Unit::TestCase
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def test_each_declaration
|
47
|
-
expected = [
|
48
|
+
expected = Set.new([
|
48
49
|
{:property => 'margin', :value => '1px -0.25em', :is_important => false},
|
49
50
|
{:property => 'background', :value => 'white none no-repeat', :is_important => true},
|
50
51
|
{:property => 'color', :value => '#fff', :is_important => false}
|
51
|
-
]
|
52
|
+
])
|
52
53
|
|
53
|
-
actual =
|
54
|
+
actual = Set.new
|
54
55
|
rs = RuleSet.new(nil, 'color: #fff; Background: white none no-repeat !important; margin: 1px -0.25em;')
|
55
56
|
rs.each_declaration do |prop, val, imp|
|
56
57
|
actual << {:property => prop, :value => val, :is_important => imp}
|
data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_rule_set_creating_shorthand.rb
RENAMED
File without changes
|
data/vendor/gems/{css_parser-0.9.1 → css_parser-1.0.0}/test/test_rule_set_expanding_shorthand.rb
RENAMED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deadweight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aanand Prasad
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-18 00:00:00 -05:00
|
13
13
|
default_executable: deadweight
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,28 +50,25 @@ files:
|
|
50
50
|
- test/fixtures/style.css
|
51
51
|
- test/rake_task_test.rb
|
52
52
|
- test/test_helper.rb
|
53
|
-
- vendor/gems/css_parser-0.
|
54
|
-
- vendor/gems/css_parser-0.
|
55
|
-
- vendor/gems/css_parser-0.
|
56
|
-
- vendor/gems/css_parser-0.
|
57
|
-
- vendor/gems/css_parser-0.
|
58
|
-
- vendor/gems/css_parser-0.
|
59
|
-
- vendor/gems/css_parser-0.
|
60
|
-
- vendor/gems/css_parser-0.
|
61
|
-
- vendor/gems/css_parser-0.
|
62
|
-
- vendor/gems/css_parser-0.
|
63
|
-
- vendor/gems/css_parser-0.
|
64
|
-
- vendor/gems/css_parser-0.
|
65
|
-
- vendor/gems/css_parser-0.
|
66
|
-
- vendor/gems/css_parser-0.
|
67
|
-
- vendor/gems/css_parser-0.
|
68
|
-
- vendor/gems/css_parser-0.
|
69
|
-
- vendor/gems/css_parser-0.
|
70
|
-
- vendor/gems/css_parser-0.
|
71
|
-
- vendor/gems/css_parser-0.
|
72
|
-
- vendor/gems/css_parser-0.9.1/test/test_rule_set.rb
|
73
|
-
- vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb
|
74
|
-
- vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb
|
53
|
+
- vendor/gems/css_parser-1.0.0/lib/css_parser.rb
|
54
|
+
- vendor/gems/css_parser-1.0.0/lib/css_parser/parser.rb
|
55
|
+
- vendor/gems/css_parser-1.0.0/lib/css_parser/regexps.rb
|
56
|
+
- vendor/gems/css_parser-1.0.0/lib/css_parser/rule_set.rb
|
57
|
+
- vendor/gems/css_parser-1.0.0/test/fixtures/import-circular-reference.css
|
58
|
+
- vendor/gems/css_parser-1.0.0/test/fixtures/import-with-media-types.css
|
59
|
+
- vendor/gems/css_parser-1.0.0/test/fixtures/import1.css
|
60
|
+
- vendor/gems/css_parser-1.0.0/test/fixtures/simple.css
|
61
|
+
- vendor/gems/css_parser-1.0.0/test/fixtures/subdir/import2.css
|
62
|
+
- vendor/gems/css_parser-1.0.0/test/test_css_parser_basic.rb
|
63
|
+
- vendor/gems/css_parser-1.0.0/test/test_css_parser_downloading.rb
|
64
|
+
- vendor/gems/css_parser-1.0.0/test/test_css_parser_media_types.rb
|
65
|
+
- vendor/gems/css_parser-1.0.0/test/test_css_parser_misc.rb
|
66
|
+
- vendor/gems/css_parser-1.0.0/test/test_css_parser_regexps.rb
|
67
|
+
- vendor/gems/css_parser-1.0.0/test/test_helper.rb
|
68
|
+
- vendor/gems/css_parser-1.0.0/test/test_merging.rb
|
69
|
+
- vendor/gems/css_parser-1.0.0/test/test_rule_set.rb
|
70
|
+
- vendor/gems/css_parser-1.0.0/test/test_rule_set_creating_shorthand.rb
|
71
|
+
- vendor/gems/css_parser-1.0.0/test/test_rule_set_expanding_shorthand.rb
|
75
72
|
has_rdoc: true
|
76
73
|
homepage: http://github.com/aanand/deadweight
|
77
74
|
licenses: []
|
@@ -1,13 +0,0 @@
|
|
1
|
-
=== Ruby CSS Parser CHANGELOG
|
2
|
-
|
3
|
-
==== Version 0.9.1
|
4
|
-
* Fixed RuleSet#declaration_to_s so it would respect <tt>!important</tt>
|
5
|
-
rules (thanks to Dana - http://github.com/DanaDanger)
|
6
|
-
|
7
|
-
==== Version 0.9
|
8
|
-
* Initial version forked from Premailer project
|
9
|
-
|
10
|
-
==== TODO: Future
|
11
|
-
* border shorthand/folding support
|
12
|
-
* re-implement caching on CssParser.merge
|
13
|
-
* correctly parse http://www.webstandards.org/files/acid2/test.html
|
@@ -1,21 +0,0 @@
|
|
1
|
-
=== Ruby CSS Parser License
|
2
|
-
|
3
|
-
Copyright (c) 2007 Alex Dunae
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
@@ -1,58 +0,0 @@
|
|
1
|
-
=== Ruby CSS Parser
|
2
|
-
|
3
|
-
Load, parse and cascade CSS rule sets in Ruby.
|
4
|
-
|
5
|
-
==== Setup
|
6
|
-
|
7
|
-
Install the gem from RubyGems.
|
8
|
-
|
9
|
-
gem install css_parser
|
10
|
-
|
11
|
-
Done.
|
12
|
-
|
13
|
-
==== An example
|
14
|
-
require 'css_parser'
|
15
|
-
include CssParser
|
16
|
-
|
17
|
-
parser = CssParser::Parser.new
|
18
|
-
parser.load_file!('http://example.com/styles/style.css')
|
19
|
-
|
20
|
-
# lookup a rule by a selector
|
21
|
-
parser.find('#content')
|
22
|
-
#=> 'font-size: 13px; line-height: 1.2;'
|
23
|
-
|
24
|
-
# lookup a rule by a selector and media type
|
25
|
-
parser.find('#content', [:screen, :handheld])
|
26
|
-
|
27
|
-
# iterate through selectors by media type
|
28
|
-
parser.each_selector(:screen) do |selector, declarations, specificity|
|
29
|
-
...
|
30
|
-
end
|
31
|
-
|
32
|
-
# add a block of CSS
|
33
|
-
css = <<-EOT
|
34
|
-
body { margin: 0 1em; }
|
35
|
-
EOT
|
36
|
-
|
37
|
-
parser.add_block!(css)
|
38
|
-
|
39
|
-
# output all CSS rules in a single stylesheet
|
40
|
-
parser.to_s
|
41
|
-
=> #content { font-size: 13px; line-height: 1.2; }
|
42
|
-
body { margin: 0 1em; }
|
43
|
-
|
44
|
-
==== Testing
|
45
|
-
|
46
|
-
You can run the suite of unit tests using <tt>rake test</tt>.
|
47
|
-
|
48
|
-
The download/import tests require that WEBrick is installed. The tests set up
|
49
|
-
a temporary server on port 12000 and pull down files from the <tt>test/fixtures/</tt>
|
50
|
-
directory.
|
51
|
-
|
52
|
-
==== Credits and code
|
53
|
-
|
54
|
-
By Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-08.
|
55
|
-
|
56
|
-
Thanks to Dana (http://github.com/DanaDanger) for the 0.9.1 update.
|
57
|
-
|
58
|
-
Made on Vancouver Island.
|