color_parser 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Guardfile +2 -2
  2. data/README.md +4 -19
  3. data/color_parser.gemspec +2 -3
  4. data/lib/color_parser.rb +1 -45
  5. data/lib/color_parser/page.rb +14 -57
  6. data/lib/color_parser/stylesheet.rb +20 -82
  7. data/lib/color_parser/version.rb +1 -1
  8. data/spec/fixtures/css_color/stylesheets/color_styles.css +7 -7
  9. data/spec/fixtures/css_color/stylesheets/frequency.css +9 -9
  10. data/spec/page_spec.rb +27 -182
  11. data/spec/stylesheet_spec.rb +43 -153
  12. metadata +5 -95
  13. data/lib/color_parser/image.rb +0 -20
  14. data/lib/color_parser/request.rb +0 -21
  15. data/spec/color_parser_spec.rb +0 -88
  16. data/spec/fixtures/css/absolute.html +0 -15
  17. data/spec/fixtures/css/inline.html +0 -34
  18. data/spec/fixtures/css/inline_import.html +0 -16
  19. data/spec/fixtures/css/invalid.html +0 -15
  20. data/spec/fixtures/css/relative.html +0 -15
  21. data/spec/fixtures/css/relative_root.html +0 -15
  22. data/spec/fixtures/css/stylesheets/colors.css +0 -0
  23. data/spec/fixtures/css/stylesheets/fonts.css +0 -0
  24. data/spec/fixtures/css/stylesheets/print.css +0 -3
  25. data/spec/fixtures/css/stylesheets/screen.css +0 -16
  26. data/spec/fixtures/css_images/images/apple.png +0 -0
  27. data/spec/fixtures/css_images/images/cantaloupe.png +0 -0
  28. data/spec/fixtures/css_images/images/kiwi.jpg +0 -0
  29. data/spec/fixtures/css_images/images/mango.png +0 -0
  30. data/spec/fixtures/css_images/images/pineapple.png +0 -0
  31. data/spec/fixtures/css_images/paths.html +0 -14
  32. data/spec/fixtures/css_images/stylesheets/import_paths.css +0 -4
  33. data/spec/fixtures/css_images/stylesheets/paths.css +0 -17
  34. data/spec/fixtures/css_images/stylesheets/quotes.css +0 -14
  35. data/spec/fixtures/css_import/index.html +0 -15
  36. data/spec/fixtures/css_import/stylesheets/borders.css +0 -0
  37. data/spec/fixtures/css_import/stylesheets/colors.css +0 -0
  38. data/spec/fixtures/css_import/stylesheets/fonts.css +0 -3
  39. data/spec/fixtures/css_import/stylesheets/ie.css +0 -3
  40. data/spec/fixtures/css_import/stylesheets/images.css +0 -0
  41. data/spec/fixtures/css_import/stylesheets/master.css +0 -12
  42. data/spec/fixtures/css_import/stylesheets/print.css +0 -3
  43. data/spec/fixtures/css_import/stylesheets/screen.css +0 -12
  44. data/spec/fixtures/inline_images/absolute.html +0 -14
  45. data/spec/fixtures/inline_images/images/apple.png +0 -0
  46. data/spec/fixtures/inline_images/images/kiwi.jpg +0 -0
  47. data/spec/fixtures/inline_images/relative.html +0 -14
  48. data/spec/fixtures/inline_images/relative_root.html +0 -14
  49. data/spec/image_spec.rb +0 -33
  50. data/spec/request_spec.rb +0 -12
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.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: curb
15
+ name: stylesheet
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0.8'
21
+ version: 0.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,23 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0.8'
30
- - !ruby/object:Gem::Dependency
31
- name: nokogiri
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '1.5'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.5'
29
+ version: 0.1.3
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: rake
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -140,55 +124,17 @@ files:
140
124
  - lib/color_parser.rb
141
125
  - lib/color_parser/color.rb
142
126
  - lib/color_parser/errors.rb
143
- - lib/color_parser/image.rb
144
127
  - lib/color_parser/page.rb
145
- - lib/color_parser/request.rb
146
128
  - lib/color_parser/stylesheet.rb
147
129
  - lib/color_parser/version.rb
148
- - spec/color_parser_spec.rb
149
130
  - 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
131
  - spec/fixtures/css_color/frequency.html
161
132
  - spec/fixtures/css_color/stylesheets/color_styles.css
162
133
  - spec/fixtures/css_color/stylesheets/css_elements.css
163
134
  - spec/fixtures/css_color/stylesheets/frequency.css
164
135
  - spec/fixtures/css_color/stylesheets/imported_selectors.css
165
136
  - 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
137
  - spec/page_spec.rb
191
- - spec/request_spec.rb
192
138
  - spec/spec_helper.rb
193
139
  - spec/stubs/fake_request.rb
194
140
  - spec/stylesheet_spec.rb
@@ -219,50 +165,14 @@ signing_key:
219
165
  specification_version: 3
220
166
  summary: Finds colors on a given webpage
221
167
  test_files:
222
- - spec/color_parser_spec.rb
223
168
  - 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
169
  - spec/fixtures/css_color/frequency.html
235
170
  - spec/fixtures/css_color/stylesheets/color_styles.css
236
171
  - spec/fixtures/css_color/stylesheets/css_elements.css
237
172
  - spec/fixtures/css_color/stylesheets/frequency.css
238
173
  - spec/fixtures/css_color/stylesheets/imported_selectors.css
239
174
  - 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
175
  - spec/page_spec.rb
265
- - spec/request_spec.rb
266
176
  - spec/spec_helper.rb
267
177
  - spec/stubs/fake_request.rb
268
178
  - spec/stylesheet_spec.rb
@@ -1,20 +0,0 @@
1
- module ColorParser
2
- class Image
3
- attr_reader :url, :host, :path, :query
4
-
5
- def initialize(url)
6
- @url = url
7
- @host, @path, @query = ColorParser.parse_url(url)
8
- end
9
-
10
- def name
11
- path.split("/").last
12
- end
13
-
14
- # TODO - find colors in the image
15
- def colors
16
- []
17
- end
18
-
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- class Request
2
- def get(url)
3
- curl = Curl::Easy.perform(url) do |curl|
4
- curl.headers["User-Agent"] = user_agent
5
- curl.follow_location = true
6
- end
7
-
8
- curl.body_str
9
-
10
- rescue ColorParser::Error
11
- raise
12
-
13
- # re-raise external library errors in our namespace
14
- rescue => error
15
- raise ColorParser::Error.new("#{error.class}: #{error.message}")
16
- end
17
-
18
- def user_agent
19
- "Ruby/ColorParser Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7"
20
- end
21
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ColorParser do
4
- before(:each) do
5
- ColorParser.request = FakeRequest.new
6
- end
7
-
8
- it "should retrieve fixture" do
9
- url = "http://example.com/css/absolute.html?foo=bar"
10
- result = ColorParser.request.get(url)
11
- expect(result).to be
12
- end
13
-
14
-
15
- # parse_url
16
-
17
- it "should parse url" do
18
- url = "http://example.com/test/something/"
19
- parsed = ColorParser.parse_url(url)
20
-
21
- expect(parsed).to eq ["example.com", "/test/something/", nil]
22
- end
23
-
24
- it "should parse url with no trailing slash" do
25
- url = "http://example.com"
26
- parsed = ColorParser.parse_url(url)
27
-
28
- expect(parsed).to eq ["example.com", "/", nil]
29
- end
30
-
31
- it "should parse url with query params" do
32
- url = "http://example.com?foo=bar&baz=bar"
33
- parsed = ColorParser.parse_url(url)
34
-
35
- expect(parsed).to eq ["example.com", "/", "foo=bar&baz=bar"]
36
- end
37
-
38
-
39
- # parse_asset
40
-
41
- it "should parse asset absolute path" do
42
- doc = "http://example.com/stylesheets/base.css"
43
- asset = "http://asset.example.com/stylesheets/style.css"
44
-
45
- parsed = ColorParser.parse_asset(doc, asset)
46
- expect(parsed).to eq "http://asset.example.com/stylesheets/style.css"
47
- end
48
-
49
- it "should parse asset absolute path with query string" do
50
- doc = "http://example.com/stylesheets/base.css?foo=bar"
51
- asset = "http://asset.example.com/stylesheets/style.css?baz=bar"
52
-
53
- parsed = ColorParser.parse_asset(doc, asset)
54
- expect(parsed).to eq "http://asset.example.com/stylesheets/style.css?baz=bar"
55
- end
56
-
57
- it "should parse relative root path" do
58
- doc = "http://example.com/stylesheets/base.css"
59
- asset = "/styles/style.css"
60
-
61
- parsed = ColorParser.parse_asset(doc, asset)
62
- expect(parsed).to eq "http://example.com/styles/style.css"
63
- end
64
-
65
- it "should parse relative root path with query string" do
66
- doc = "http://example.com/stylesheets/base.css?foo=bar"
67
- asset = "/styles/style.css?baz=bar"
68
-
69
- parsed = ColorParser.parse_asset(doc, asset)
70
- expect(parsed).to eq "http://example.com/styles/style.css?baz=bar"
71
- end
72
-
73
- it "should parse relative path" do
74
- doc = "http://example.com/stylesheets/base.css"
75
- asset = "ie.css"
76
-
77
- parsed = ColorParser.parse_asset(doc, asset)
78
- expect(parsed).to eq "http://example.com/stylesheets/ie.css"
79
- end
80
-
81
- it "should parse relative path with query string" do
82
- doc = "http://example.com/stylesheets/base.css?foo=bar"
83
- asset = "ie.css?baz=bar"
84
-
85
- parsed = ColorParser.parse_asset(doc, asset)
86
- expect(parsed).to eq "http://example.com/stylesheets/ie.css?baz=bar"
87
- end
88
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
-
9
- <link rel="stylesheet" href="http://example.com/css/stylesheets/screen.css" media="screen" type="text/css" />
10
- <link rel="stylesheet" href="http://example.com/css/stylesheets/print.css" media="print" type="text/css" />
11
- </head>
12
- <body>
13
- <div></div>
14
- </body>
15
- </html>
@@ -1,34 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
- <style>
9
- body {
10
- color: #444;
11
- background-color: #535353;
12
- }
13
- a:link {
14
- color: #357ad1;
15
- }
16
- a:visited {
17
- color: #77abf0;
18
- }
19
- a:hover {
20
- color: #333;
21
- }
22
- </style>
23
- </head>
24
- <body>
25
- <style>
26
- div {
27
- background-color: #aaa;
28
- border: 1px solid #ccc;
29
- }
30
- </style>
31
-
32
- <div></div>
33
- </body>
34
- </html>
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
- <style>
9
- @import "stylesheets/print.css";@import url "stylesheets/fonts.css"
10
- @import url("stylesheets/colors.css")
11
- </style>
12
- </head>
13
- <body>
14
- <div></div>
15
- </body>
16
- </html>
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
-
9
- <link rel="stylesheet" href="stylesheets/asdf.css" media="screen" type="text/css" />
10
- <link rel="stylesheet" href="stylesheets/screen.css" media="screen" type="text/css" />
11
- </head>
12
- <body>
13
- <div></div>
14
- </body>
15
- </html>
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
-
9
- <link rel="stylesheet" href="stylesheets/screen.css" media="screen" type="text/css" />
10
- <link rel="stylesheet" href="stylesheets/print.css" media="print" type="text/css" />
11
- </head>
12
- <body>
13
- <div></div>
14
- </body>
15
- </html>
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
4
-
5
- <head>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
7
- <title>Color Parser</title>
8
-
9
- <link rel="stylesheet" href="/css/stylesheets/screen.css" media="screen" type="text/css" />
10
- <link rel="stylesheet" href="/css/stylesheets/print.css" media="print" type="text/css" />
11
- </head>
12
- <body>
13
- <div></div>
14
- </body>
15
- </html>
File without changes
File without changes
@@ -1,3 +0,0 @@
1
- body {
2
- margin: 0;
3
- }
@@ -1,16 +0,0 @@
1
- body {
2
- color: #444;
3
- background-color: #535353;
4
- }
5
- a:link {
6
- color: #357ad1;
7
- }
8
- a:visited {
9
- color: #77abf0;
10
- }
11
- a:hover {
12
- color: #333;
13
- }
14
- .shade {
15
- background-color: #f5f5f5;
16
- }