css_parser_master 1.2.4
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/.gitignore +4 -0
- data/CHANGELOG +34 -0
- data/LICENSE +21 -0
- data/README +0 -0
- data/README.rdoc +77 -0
- data/Rakefile.rb +18 -0
- data/VERSION +1 -0
- data/lib/css_parser_master.rb +156 -0
- data/lib/css_parser_master/declaration.rb +31 -0
- data/lib/css_parser_master/declaration_api.rb +91 -0
- data/lib/css_parser_master/declarations.rb +23 -0
- data/lib/css_parser_master/parser.rb +388 -0
- data/lib/css_parser_master/regexps.rb +46 -0
- data/lib/css_parser_master/rule_set.rb +337 -0
- data/lib/css_parser_master/selector.rb +33 -0
- data/lib/css_parser_master/selectors.rb +27 -0
- data/test/fixtures/import-circular-reference.css +4 -0
- data/test/fixtures/import-with-media-types.css +3 -0
- data/test/fixtures/import1.css +3 -0
- data/test/fixtures/simple.css +6 -0
- data/test/fixtures/subdir/import2.css +3 -0
- data/test/test_css_parser_basic.rb +84 -0
- data/test/test_css_parser_loading.rb +110 -0
- data/test/test_css_parser_media_types.rb +71 -0
- data/test/test_css_parser_misc.rb +151 -0
- data/test/test_css_parser_regexps.rb +69 -0
- data/test/test_helper.rb +6 -0
- data/test/test_merging.rb +88 -0
- data/test/test_rule_set.rb +90 -0
- data/test/test_rule_set_creating_shorthand.rb +90 -0
- data/test/test_rule_set_expanding_shorthand.rb +179 -0
- data/test/test_ruleset_expand.rb +40 -0
- data/test/test_selector.rb +26 -0
- data/test/test_selector_parsing.rb +27 -0
- metadata +112 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RuleSetExpandingShorthandTests < Test::Unit::TestCase
|
4
|
+
include CssParser
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@cp = CssParser::Parser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# ==== Dimensions shorthand
|
11
|
+
def test_getting_dimensions_from_shorthand
|
12
|
+
# test various shorthand forms
|
13
|
+
['margin: 0px auto', 'margin: 0px auto 0px', 'margin: 0px auto 0px'].each do |shorthand|
|
14
|
+
declarations = expand_declarations(shorthand)
|
15
|
+
assert_equal({"margin-right" => "auto", "margin-bottom" => "0px", "margin-left" => "auto", "margin-top" => "0px"}, declarations)
|
16
|
+
end
|
17
|
+
|
18
|
+
# test various units
|
19
|
+
['em', 'ex', 'in', 'px', 'pt', 'pc', '%'].each do |unit|
|
20
|
+
shorthand = "margin: 0% -0.123#{unit} 9px -.9pc"
|
21
|
+
declarations = expand_declarations(shorthand)
|
22
|
+
assert_equal({"margin-right" => "-0.123#{unit}", "margin-bottom" => "9px", "margin-left" => "-.9pc", "margin-top" => "0%"}, declarations)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
protected
|
28
|
+
def expand_declarations(declarations)
|
29
|
+
ruleset = RuleSet.new(nil, declarations)
|
30
|
+
ruleset.expand_shorthand!
|
31
|
+
|
32
|
+
collected = {}
|
33
|
+
|
34
|
+
# ruleset.each_declaration do |prop, val, imp|
|
35
|
+
ruleset.each_declaration do |decl|
|
36
|
+
collected[decl.property.to_s] = decl.value.to_s
|
37
|
+
end
|
38
|
+
collected
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
# Test cases for the CssParser.
|
4
|
+
class CssSelectorTests < Test::Unit::TestCase
|
5
|
+
include CssParser
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cp = Parser.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_at_page_rule
|
12
|
+
# from http://www.w3.org/TR/CSS21/page.html#page-selectors
|
13
|
+
css = <<-EOT
|
14
|
+
@page { margin: 2cm }
|
15
|
+
|
16
|
+
@page :first {
|
17
|
+
margin-top: 10cm
|
18
|
+
}
|
19
|
+
EOT
|
20
|
+
|
21
|
+
@cp.add_block!(css)
|
22
|
+
|
23
|
+
assert_equal 'margin: 2cm;', @cp.find_by_selector('@page').join(' ')
|
24
|
+
# assert_equal 'margin-top: 10cm;', @cp.find_by_selector('@page :first').join(' ')
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
# Test cases for reading and generating CSS shorthand properties
|
4
|
+
class CssSelectorParserTests < Test::Unit::TestCase
|
5
|
+
include CssParser
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cp = CssParser::Parser.new
|
9
|
+
@css = <<-EOT
|
10
|
+
html, body, p { margin: 0px; }
|
11
|
+
p { padding: 0px; }
|
12
|
+
#content { font: 12px/normal sans-serif; }
|
13
|
+
EOT
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_selector_parser
|
17
|
+
selector = CssParser::Selector.new('table', 'margin: 0px', 9999)
|
18
|
+
# puts selector.inspect
|
19
|
+
|
20
|
+
selector.each_declaration do |decl|
|
21
|
+
# puts decl.inspect
|
22
|
+
end
|
23
|
+
|
24
|
+
selector = CssParser::Selector.new('table', 'margin: 0px; padding: 0px;', 9999)
|
25
|
+
# puts selector.inspect
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: css_parser_master
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 4
|
9
|
+
version: 1.2.4
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
- Alex Dunae
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-27 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Parse a CSS file and access/operate on rulesets, selectors, declarations etc. Includes specificity calculated according to W3C spec.
|
23
|
+
email: kmandrup@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- CHANGELOG
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile.rb
|
39
|
+
- VERSION
|
40
|
+
- lib/css_parser_master.rb
|
41
|
+
- lib/css_parser_master/declaration.rb
|
42
|
+
- lib/css_parser_master/declaration_api.rb
|
43
|
+
- lib/css_parser_master/declarations.rb
|
44
|
+
- lib/css_parser_master/parser.rb
|
45
|
+
- lib/css_parser_master/regexps.rb
|
46
|
+
- lib/css_parser_master/rule_set.rb
|
47
|
+
- lib/css_parser_master/selector.rb
|
48
|
+
- lib/css_parser_master/selectors.rb
|
49
|
+
- test/fixtures/import-circular-reference.css
|
50
|
+
- test/fixtures/import-with-media-types.css
|
51
|
+
- test/fixtures/import1.css
|
52
|
+
- test/fixtures/simple.css
|
53
|
+
- test/fixtures/subdir/import2.css
|
54
|
+
- test/test_css_parser_basic.rb
|
55
|
+
- test/test_css_parser_loading.rb
|
56
|
+
- test/test_css_parser_media_types.rb
|
57
|
+
- test/test_css_parser_misc.rb
|
58
|
+
- test/test_css_parser_regexps.rb
|
59
|
+
- test/test_helper.rb
|
60
|
+
- test/test_merging.rb
|
61
|
+
- test/test_rule_set.rb
|
62
|
+
- test/test_rule_set_creating_shorthand.rb
|
63
|
+
- test/test_rule_set_expanding_shorthand.rb
|
64
|
+
- test/test_ruleset_expand.rb
|
65
|
+
- test/test_selector.rb
|
66
|
+
- test/test_selector_parsing.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/kristianmandrup/load-me
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Parse CSS files, access and operate on a model of the CSS rules
|
99
|
+
test_files:
|
100
|
+
- test/test_css_parser_basic.rb
|
101
|
+
- test/test_css_parser_loading.rb
|
102
|
+
- test/test_css_parser_media_types.rb
|
103
|
+
- test/test_css_parser_misc.rb
|
104
|
+
- test/test_css_parser_regexps.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
- test/test_merging.rb
|
107
|
+
- test/test_rule_set.rb
|
108
|
+
- test/test_rule_set_creating_shorthand.rb
|
109
|
+
- test/test_rule_set_expanding_shorthand.rb
|
110
|
+
- test/test_ruleset_expand.rb
|
111
|
+
- test/test_selector.rb
|
112
|
+
- test/test_selector_parsing.rb
|