color_parser 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Guardfile +9 -0
- data/README.md +22 -22
- data/Rakefile +18 -6
- data/color_parser.gemspec +9 -1
- data/lib/color_parser/color.rb +154 -0
- data/lib/color_parser/errors.rb +3 -0
- data/lib/color_parser/request.rb +21 -0
- data/lib/color_parser/stylesheet.rb +4 -11
- data/lib/color_parser/version.rb +1 -1
- data/lib/color_parser.rb +4 -89
- data/{test/color_parser_test.rb → spec/color_parser_spec.rb} +19 -14
- data/spec/color_spec.rb +10 -0
- data/{test → spec}/fixtures/css/absolute.html +0 -0
- data/{test → spec}/fixtures/css/inline.html +0 -0
- data/{test → spec}/fixtures/css/inline_import.html +0 -0
- data/{test → spec}/fixtures/css/invalid.html +0 -0
- data/{test → spec}/fixtures/css/relative.html +0 -0
- data/{test → spec}/fixtures/css/relative_root.html +0 -0
- data/{test → spec}/fixtures/css/stylesheets/colors.css +0 -0
- data/{test → spec}/fixtures/css/stylesheets/fonts.css +0 -0
- data/{test → spec}/fixtures/css/stylesheets/print.css +0 -0
- data/{test → spec}/fixtures/css/stylesheets/screen.css +0 -0
- data/{test → spec}/fixtures/css_color/frequency.html +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/color_styles.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/css_elements.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/frequency.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/imported_selectors.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/properties.css +0 -0
- data/{test → spec}/fixtures/css_images/images/apple.png +0 -0
- data/{test → spec}/fixtures/css_images/images/cantaloupe.png +0 -0
- data/{test → spec}/fixtures/css_images/images/kiwi.jpg +0 -0
- data/{test → spec}/fixtures/css_images/images/mango.png +0 -0
- data/{test → spec}/fixtures/css_images/images/pineapple.png +0 -0
- data/{test → spec}/fixtures/css_images/paths.html +0 -0
- data/{test → spec}/fixtures/css_images/stylesheets/import_paths.css +0 -0
- data/{test → spec}/fixtures/css_images/stylesheets/paths.css +0 -0
- data/{test → spec}/fixtures/css_images/stylesheets/quotes.css +0 -0
- data/{test → spec}/fixtures/css_import/index.html +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/borders.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/colors.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/fonts.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/ie.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/images.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/master.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/print.css +0 -0
- data/{test → spec}/fixtures/css_import/stylesheets/screen.css +0 -0
- data/{test → spec}/fixtures/inline_images/absolute.html +0 -0
- data/{test → spec}/fixtures/inline_images/images/apple.png +0 -0
- data/{test → spec}/fixtures/inline_images/images/kiwi.jpg +0 -0
- data/{test → spec}/fixtures/inline_images/relative.html +0 -0
- data/{test → spec}/fixtures/inline_images/relative_root.html +0 -0
- data/spec/image_spec.rb +33 -0
- data/{test/page_test.rb → spec/page_spec.rb} +57 -57
- data/spec/request_spec.rb +12 -0
- data/spec/spec_helper.rb +10 -0
- data/{test/test_request.rb → spec/stubs/fake_request.rb} +2 -2
- data/spec/stylesheet_spec.rb +235 -0
- data/spec/version_spec.rb +9 -0
- metadata +186 -100
- data/test/image_test.rb +0 -27
- data/test/stylesheet_test.rb +0 -257
- data/test/test_helper.rb +0 -6
- data/test/version_test.rb +0 -7
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: curb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: nokogiri
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,7 +59,71 @@ dependencies:
|
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
46
|
-
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.9'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.9'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.7'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.7'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.5'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.5'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rb-fsevent
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.9'
|
126
|
+
description: Finds colors on a given webpage
|
47
127
|
email:
|
48
128
|
- derek@sportspyder.com
|
49
129
|
executables: []
|
@@ -52,61 +132,67 @@ extra_rdoc_files: []
|
|
52
132
|
files:
|
53
133
|
- .gitignore
|
54
134
|
- Gemfile
|
135
|
+
- Guardfile
|
55
136
|
- LICENSE.txt
|
56
137
|
- README.md
|
57
138
|
- Rakefile
|
58
139
|
- color_parser.gemspec
|
59
140
|
- lib/color_parser.rb
|
141
|
+
- lib/color_parser/color.rb
|
142
|
+
- lib/color_parser/errors.rb
|
60
143
|
- lib/color_parser/image.rb
|
61
144
|
- lib/color_parser/page.rb
|
145
|
+
- lib/color_parser/request.rb
|
62
146
|
- lib/color_parser/stylesheet.rb
|
63
147
|
- lib/color_parser/version.rb
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
148
|
+
- spec/color_parser_spec.rb
|
149
|
+
- spec/color_spec.rb
|
150
|
+
- spec/fixtures/css/absolute.html
|
151
|
+
- spec/fixtures/css/inline.html
|
152
|
+
- spec/fixtures/css/inline_import.html
|
153
|
+
- spec/fixtures/css/invalid.html
|
154
|
+
- spec/fixtures/css/relative.html
|
155
|
+
- spec/fixtures/css/relative_root.html
|
156
|
+
- spec/fixtures/css/stylesheets/colors.css
|
157
|
+
- spec/fixtures/css/stylesheets/fonts.css
|
158
|
+
- spec/fixtures/css/stylesheets/print.css
|
159
|
+
- spec/fixtures/css/stylesheets/screen.css
|
160
|
+
- spec/fixtures/css_color/frequency.html
|
161
|
+
- spec/fixtures/css_color/stylesheets/color_styles.css
|
162
|
+
- spec/fixtures/css_color/stylesheets/css_elements.css
|
163
|
+
- spec/fixtures/css_color/stylesheets/frequency.css
|
164
|
+
- spec/fixtures/css_color/stylesheets/imported_selectors.css
|
165
|
+
- spec/fixtures/css_color/stylesheets/properties.css
|
166
|
+
- spec/fixtures/css_images/images/apple.png
|
167
|
+
- spec/fixtures/css_images/images/cantaloupe.png
|
168
|
+
- spec/fixtures/css_images/images/kiwi.jpg
|
169
|
+
- spec/fixtures/css_images/images/mango.png
|
170
|
+
- spec/fixtures/css_images/images/pineapple.png
|
171
|
+
- spec/fixtures/css_images/paths.html
|
172
|
+
- spec/fixtures/css_images/stylesheets/import_paths.css
|
173
|
+
- spec/fixtures/css_images/stylesheets/paths.css
|
174
|
+
- spec/fixtures/css_images/stylesheets/quotes.css
|
175
|
+
- spec/fixtures/css_import/index.html
|
176
|
+
- spec/fixtures/css_import/stylesheets/borders.css
|
177
|
+
- spec/fixtures/css_import/stylesheets/colors.css
|
178
|
+
- spec/fixtures/css_import/stylesheets/fonts.css
|
179
|
+
- spec/fixtures/css_import/stylesheets/ie.css
|
180
|
+
- spec/fixtures/css_import/stylesheets/images.css
|
181
|
+
- spec/fixtures/css_import/stylesheets/master.css
|
182
|
+
- spec/fixtures/css_import/stylesheets/print.css
|
183
|
+
- spec/fixtures/css_import/stylesheets/screen.css
|
184
|
+
- spec/fixtures/inline_images/absolute.html
|
185
|
+
- spec/fixtures/inline_images/images/apple.png
|
186
|
+
- spec/fixtures/inline_images/images/kiwi.jpg
|
187
|
+
- spec/fixtures/inline_images/relative.html
|
188
|
+
- spec/fixtures/inline_images/relative_root.html
|
189
|
+
- spec/image_spec.rb
|
190
|
+
- spec/page_spec.rb
|
191
|
+
- spec/request_spec.rb
|
192
|
+
- spec/spec_helper.rb
|
193
|
+
- spec/stubs/fake_request.rb
|
194
|
+
- spec/stylesheet_spec.rb
|
195
|
+
- spec/version_spec.rb
|
110
196
|
homepage: https://github.com/devrieda/color_parser
|
111
197
|
licenses:
|
112
198
|
- MIT
|
@@ -126,59 +212,59 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
212
|
- - ! '>='
|
127
213
|
- !ruby/object:Gem::Version
|
128
214
|
version: '0'
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
hash: -3886628688892773367
|
132
215
|
requirements: []
|
133
216
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.8.
|
217
|
+
rubygems_version: 1.8.25
|
135
218
|
signing_key:
|
136
219
|
specification_version: 3
|
137
|
-
summary:
|
220
|
+
summary: Finds colors on a given webpage
|
138
221
|
test_files:
|
139
|
-
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
-
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
162
|
-
-
|
163
|
-
-
|
164
|
-
-
|
165
|
-
-
|
166
|
-
-
|
167
|
-
-
|
168
|
-
-
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
222
|
+
- spec/color_parser_spec.rb
|
223
|
+
- spec/color_spec.rb
|
224
|
+
- spec/fixtures/css/absolute.html
|
225
|
+
- spec/fixtures/css/inline.html
|
226
|
+
- spec/fixtures/css/inline_import.html
|
227
|
+
- spec/fixtures/css/invalid.html
|
228
|
+
- spec/fixtures/css/relative.html
|
229
|
+
- spec/fixtures/css/relative_root.html
|
230
|
+
- spec/fixtures/css/stylesheets/colors.css
|
231
|
+
- spec/fixtures/css/stylesheets/fonts.css
|
232
|
+
- spec/fixtures/css/stylesheets/print.css
|
233
|
+
- spec/fixtures/css/stylesheets/screen.css
|
234
|
+
- spec/fixtures/css_color/frequency.html
|
235
|
+
- spec/fixtures/css_color/stylesheets/color_styles.css
|
236
|
+
- spec/fixtures/css_color/stylesheets/css_elements.css
|
237
|
+
- spec/fixtures/css_color/stylesheets/frequency.css
|
238
|
+
- spec/fixtures/css_color/stylesheets/imported_selectors.css
|
239
|
+
- spec/fixtures/css_color/stylesheets/properties.css
|
240
|
+
- spec/fixtures/css_images/images/apple.png
|
241
|
+
- spec/fixtures/css_images/images/cantaloupe.png
|
242
|
+
- spec/fixtures/css_images/images/kiwi.jpg
|
243
|
+
- spec/fixtures/css_images/images/mango.png
|
244
|
+
- spec/fixtures/css_images/images/pineapple.png
|
245
|
+
- spec/fixtures/css_images/paths.html
|
246
|
+
- spec/fixtures/css_images/stylesheets/import_paths.css
|
247
|
+
- spec/fixtures/css_images/stylesheets/paths.css
|
248
|
+
- spec/fixtures/css_images/stylesheets/quotes.css
|
249
|
+
- spec/fixtures/css_import/index.html
|
250
|
+
- spec/fixtures/css_import/stylesheets/borders.css
|
251
|
+
- spec/fixtures/css_import/stylesheets/colors.css
|
252
|
+
- spec/fixtures/css_import/stylesheets/fonts.css
|
253
|
+
- spec/fixtures/css_import/stylesheets/ie.css
|
254
|
+
- spec/fixtures/css_import/stylesheets/images.css
|
255
|
+
- spec/fixtures/css_import/stylesheets/master.css
|
256
|
+
- spec/fixtures/css_import/stylesheets/print.css
|
257
|
+
- spec/fixtures/css_import/stylesheets/screen.css
|
258
|
+
- spec/fixtures/inline_images/absolute.html
|
259
|
+
- spec/fixtures/inline_images/images/apple.png
|
260
|
+
- spec/fixtures/inline_images/images/kiwi.jpg
|
261
|
+
- spec/fixtures/inline_images/relative.html
|
262
|
+
- spec/fixtures/inline_images/relative_root.html
|
263
|
+
- spec/image_spec.rb
|
264
|
+
- spec/page_spec.rb
|
265
|
+
- spec/request_spec.rb
|
266
|
+
- spec/spec_helper.rb
|
267
|
+
- spec/stubs/fake_request.rb
|
268
|
+
- spec/stylesheet_spec.rb
|
269
|
+
- spec/version_spec.rb
|
270
|
+
has_rdoc:
|
data/test/image_test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
describe Image do
|
4
|
-
def setup
|
5
|
-
ColorParser.request = ColorParser::TestRequest.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should assign url" do
|
9
|
-
image = ColorParser::Image.new("http://example.com/foo/bar.png")
|
10
|
-
|
11
|
-
image.url.must_equal "http://example.com/foo/bar.png"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should parse host path and query from url" do
|
15
|
-
image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
|
16
|
-
|
17
|
-
image.host.must_equal "example.com"
|
18
|
-
image.path.must_equal "/foo/bar.png"
|
19
|
-
image.query.must_equal "baz=bar"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should parse name" do
|
23
|
-
image = ColorParser::Image.new("http://example.com/foo/bar.png?baz=bar")
|
24
|
-
|
25
|
-
"bar.png".must_equal image.name
|
26
|
-
end
|
27
|
-
end
|
data/test/stylesheet_test.rb
DELETED
@@ -1,257 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
describe Stylesheet do
|
4
|
-
def setup
|
5
|
-
ColorParser.request = ColorParser::TestRequest.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "must initialize params" do
|
9
|
-
sheet = ColorParser::Stylesheet.new(text: "a { background: #fff; }",
|
10
|
-
type: "inline",
|
11
|
-
url: "http://example.com/css/inline.html?foo=bar")
|
12
|
-
sheet.type.must_equal "inline"
|
13
|
-
sheet.text.must_equal "a { background: #fff; }"
|
14
|
-
sheet.url.must_equal "http://example.com/css/inline.html?foo=bar"
|
15
|
-
sheet.host.must_equal "example.com"
|
16
|
-
sheet.path.must_equal "/css/inline.html"
|
17
|
-
sheet.query.must_equal "foo=bar"
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
# Import Quoting
|
22
|
-
|
23
|
-
it "should import stylesheets with double quotes" do
|
24
|
-
css = style("/css_import/stylesheets/screen.css")
|
25
|
-
|
26
|
-
imported = css.stylesheets[0]
|
27
|
-
imported.name.must_equal "master.css"
|
28
|
-
imported.text.must_include "a:link"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should import stylesheets with single quotes" do
|
32
|
-
css = style("/css_import/stylesheets/screen.css")
|
33
|
-
|
34
|
-
imported = css.stylesheets[1]
|
35
|
-
imported.name.must_equal "fonts.css"
|
36
|
-
imported.text.must_include "font-family"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should import stylesheets with no quotes" do
|
40
|
-
css = style("/css_import/stylesheets/screen.css")
|
41
|
-
|
42
|
-
imported = css.stylesheets[2]
|
43
|
-
imported.name.must_equal "ie.css"
|
44
|
-
imported.text.must_include "background-color"
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
# Import Paths
|
49
|
-
|
50
|
-
it "should import from relative path" do
|
51
|
-
css = style("/css_import/stylesheets/screen.css")
|
52
|
-
|
53
|
-
imported = css.stylesheets[0]
|
54
|
-
imported.url.must_equal "http://example.com/css_import/stylesheets/master.css"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should import from relative root path" do
|
58
|
-
css = style("/css_import/stylesheets/screen.css")
|
59
|
-
|
60
|
-
imported = css.stylesheets[1]
|
61
|
-
imported.url.must_equal "http://example.com/css_import/stylesheets/fonts.css"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should import from absolute path" do
|
65
|
-
css = style("/css_import/stylesheets/screen.css")
|
66
|
-
|
67
|
-
imported = css.stylesheets[2]
|
68
|
-
imported.url.must_equal "http://example.com/css_import/stylesheets/ie.css"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should not fail on invalid import path" do
|
72
|
-
css = style("/css_import/stylesheets/screen.css")
|
73
|
-
css.stylesheets[6].must_be_nil
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
# Selector parsing
|
78
|
-
|
79
|
-
it "should parse selectors" do
|
80
|
-
css = style("/css_color/stylesheets/properties.css")
|
81
|
-
selectors = css.selectors
|
82
|
-
|
83
|
-
selectors.size.must_equal 4
|
84
|
-
|
85
|
-
selectors["p"].size.must_equal 2
|
86
|
-
selectors["div"].size.must_equal 1
|
87
|
-
selectors["h1"].size.must_equal 2
|
88
|
-
|
89
|
-
# imported
|
90
|
-
selectors["dl"].size.must_equal 1
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should parse properties" do
|
94
|
-
css = style("/css_color/stylesheets/properties.css")
|
95
|
-
props = css.properties
|
96
|
-
|
97
|
-
props.size.must_equal 9
|
98
|
-
|
99
|
-
props.must_include ["background", "#000"]
|
100
|
-
props.must_include ["color", "#fff"]
|
101
|
-
props.must_include ["margin", "0"]
|
102
|
-
props.must_include ["background-color", "#ccc"]
|
103
|
-
props.must_include ["font-size", "100%"]
|
104
|
-
props.must_include ["border-color", "rgb(1,2,3)"]
|
105
|
-
|
106
|
-
# imported
|
107
|
-
props.must_include ["border", "1px solid red"]
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
# Color Parsing
|
112
|
-
|
113
|
-
it "should parse hex colors" do
|
114
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
115
|
-
|
116
|
-
css.colors["386ec0"].wont_be_nil # 386ec0
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should parse hex short colors" do
|
120
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
121
|
-
|
122
|
-
css.colors["cc00cc"].wont_be_nil # c0c
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should parse textual colors" do
|
126
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
127
|
-
|
128
|
-
css.colors["008080"].wont_be_nil # teal
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should parse rgb colors" do
|
132
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
133
|
-
|
134
|
-
css.colors["718ad7"].wont_be_nil # rgb(113,138,215)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should parse rgb colors with space" do
|
138
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
139
|
-
|
140
|
-
css.colors["3a5dc4"].wont_be_nil # rgb(58, 93, 196)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should parse rgba colors" do
|
144
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
145
|
-
|
146
|
-
css.colors["29469e"].wont_be_nil # rgba(41,70,158,0.5);
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should parse rgba colors with space" do
|
150
|
-
css = style("/css_color/stylesheets/color_styles.css")
|
151
|
-
|
152
|
-
css.colors["3f6aeb"].wont_be_nil # rgba(63, 106, 235, 0.5);
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
# Color weighting
|
157
|
-
|
158
|
-
it "should order colors by frequency" do
|
159
|
-
css = style("/css_color/stylesheets/frequency.css")
|
160
|
-
|
161
|
-
colors = {"386ec0" => 4, "3a5dc4" => 3,
|
162
|
-
"718ad7" => 2, "ff0000" => 1}
|
163
|
-
css.colors.must_equal colors
|
164
|
-
end
|
165
|
-
|
166
|
-
# BG colors
|
167
|
-
it "should order background colors by frequency" do
|
168
|
-
css = style("/css_color/stylesheets/frequency.css")
|
169
|
-
|
170
|
-
colors = {"386ec0" => 2, "3a5dc4" => 1}
|
171
|
-
css.bg_colors.must_equal colors
|
172
|
-
end
|
173
|
-
|
174
|
-
# Text colors
|
175
|
-
it "should order text colors by frequency" do
|
176
|
-
css = style("/css_color/stylesheets/frequency.css")
|
177
|
-
|
178
|
-
colors = {"386ec0" => 2, "718ad7" => 1}
|
179
|
-
css.text_colors.must_equal colors
|
180
|
-
end
|
181
|
-
|
182
|
-
# Border colors
|
183
|
-
it "should order border colors by frequency" do
|
184
|
-
css = style("/css_color/stylesheets/frequency.css")
|
185
|
-
|
186
|
-
colors = {"3a5dc4" => 2, "ff0000" => 1, "718ad7" => 1}
|
187
|
-
css.border_colors.must_equal colors
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
# Images Parsing
|
192
|
-
|
193
|
-
it "should parse images with double quotes" do
|
194
|
-
css = style("/css_images/stylesheets/quotes.css")
|
195
|
-
|
196
|
-
css.images[0].name.must_equal "apple.png"
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should parse images with single quotes" do
|
200
|
-
css = style("/css_images/stylesheets/quotes.css")
|
201
|
-
|
202
|
-
css.images[1].name.must_equal "kiwi.jpg"
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should parse images with no quotes" do
|
206
|
-
css = style("/css_images/stylesheets/quotes.css")
|
207
|
-
|
208
|
-
css.images[2].name.must_equal "cantaloupe.png"
|
209
|
-
end
|
210
|
-
|
211
|
-
|
212
|
-
# Image paths
|
213
|
-
|
214
|
-
it "should build image from absolute path" do
|
215
|
-
css = style("/css_images/stylesheets/paths.css")
|
216
|
-
urls = css.images.map {|image| image.url }
|
217
|
-
|
218
|
-
urls.size.must_equal 4
|
219
|
-
urls.must_include "http://example.com/css_images/images/apple.png"
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should build image from relative path" do
|
223
|
-
css = style("/css_images/stylesheets/paths.css")
|
224
|
-
urls = css.images.map {|image| image.url }
|
225
|
-
|
226
|
-
urls.size.must_equal 4
|
227
|
-
urls.must_include "http://example.com/css_images/images/kiwi.jpg"
|
228
|
-
end
|
229
|
-
|
230
|
-
it "should build image from relative root path" do
|
231
|
-
css = style("/css_images/stylesheets/paths.css")
|
232
|
-
urls = css.images.map {|image| image.url }
|
233
|
-
|
234
|
-
urls.size.must_equal 4
|
235
|
-
urls.must_include "http://example.com/css_images/images/cantaloupe.png"
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should build image from imported path" do
|
239
|
-
css = style("/css_images/stylesheets/paths.css")
|
240
|
-
urls = css.images.map {|image| image.url }
|
241
|
-
|
242
|
-
urls.size.must_equal 4
|
243
|
-
urls.must_include "http://example.com/css_images/images/pineapple.png"
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
private
|
248
|
-
|
249
|
-
def style(path)
|
250
|
-
ColorParser::Stylesheet.new(text: fixture(path),
|
251
|
-
url: "http://example.com#{path}")
|
252
|
-
end
|
253
|
-
|
254
|
-
def fixture(path)
|
255
|
-
fixture = "#{File.dirname(__FILE__)}/../test/fixtures#{path}"
|
256
|
-
File.read(fixture) if File.exist?(fixture)
|
257
|
-
end
|
data/test/test_helper.rb
DELETED