color_parser 0.1.0 → 1.0.5
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.
- checksums.yaml +7 -0
- data/Gemfile +0 -2
- data/Guardfile +2 -2
- data/README.md +9 -18
- data/color_parser.gemspec +3 -3
- data/lib/color_parser.rb +2 -48
- data/lib/color_parser/page.rb +14 -57
- data/lib/color_parser/stylesheet.rb +27 -116
- data/lib/color_parser/version.rb +1 -1
- data/spec/fixtures/css_color/stylesheets/color_styles.css +7 -7
- data/spec/fixtures/css_color/stylesheets/frequency.css +9 -9
- data/spec/page_spec.rb +27 -182
- data/spec/stylesheet_spec.rb +43 -153
- metadata +31 -126
- data/lib/color_parser/color.rb +0 -154
- data/lib/color_parser/image.rb +0 -20
- data/lib/color_parser/request.rb +0 -21
- data/spec/color_parser_spec.rb +0 -88
- data/spec/color_spec.rb +0 -10
- data/spec/fixtures/css/absolute.html +0 -15
- data/spec/fixtures/css/inline.html +0 -34
- data/spec/fixtures/css/inline_import.html +0 -16
- data/spec/fixtures/css/invalid.html +0 -15
- data/spec/fixtures/css/relative.html +0 -15
- data/spec/fixtures/css/relative_root.html +0 -15
- data/spec/fixtures/css/stylesheets/colors.css +0 -0
- data/spec/fixtures/css/stylesheets/fonts.css +0 -0
- data/spec/fixtures/css/stylesheets/print.css +0 -3
- data/spec/fixtures/css/stylesheets/screen.css +0 -16
- data/spec/fixtures/css_images/images/apple.png +0 -0
- data/spec/fixtures/css_images/images/cantaloupe.png +0 -0
- data/spec/fixtures/css_images/images/kiwi.jpg +0 -0
- data/spec/fixtures/css_images/images/mango.png +0 -0
- data/spec/fixtures/css_images/images/pineapple.png +0 -0
- data/spec/fixtures/css_images/paths.html +0 -14
- data/spec/fixtures/css_images/stylesheets/import_paths.css +0 -4
- data/spec/fixtures/css_images/stylesheets/paths.css +0 -17
- data/spec/fixtures/css_images/stylesheets/quotes.css +0 -14
- data/spec/fixtures/css_import/index.html +0 -15
- data/spec/fixtures/css_import/stylesheets/borders.css +0 -0
- data/spec/fixtures/css_import/stylesheets/colors.css +0 -0
- data/spec/fixtures/css_import/stylesheets/fonts.css +0 -3
- data/spec/fixtures/css_import/stylesheets/ie.css +0 -3
- data/spec/fixtures/css_import/stylesheets/images.css +0 -0
- data/spec/fixtures/css_import/stylesheets/master.css +0 -12
- data/spec/fixtures/css_import/stylesheets/print.css +0 -3
- data/spec/fixtures/css_import/stylesheets/screen.css +0 -12
- data/spec/fixtures/inline_images/absolute.html +0 -14
- data/spec/fixtures/inline_images/images/apple.png +0 -0
- data/spec/fixtures/inline_images/images/kiwi.jpg +0 -0
- data/spec/fixtures/inline_images/relative.html +0 -14
- data/spec/fixtures/inline_images/relative_root.html +0 -14
- data/spec/image_spec.rb +0 -33
- data/spec/request_spec.rb +0 -12
data/lib/color_parser/image.rb
DELETED
@@ -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
|
data/lib/color_parser/request.rb
DELETED
@@ -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
|
data/spec/color_parser_spec.rb
DELETED
@@ -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
|
data/spec/color_spec.rb
DELETED
@@ -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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,14 +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/paths.css" media="screen" type="text/css" />
|
10
|
-
</head>
|
11
|
-
<body>
|
12
|
-
<img src="images/mango.png" />
|
13
|
-
</body>
|
14
|
-
</html>
|
@@ -1,17 +0,0 @@
|
|
1
|
-
/* absolute */
|
2
|
-
body {
|
3
|
-
background: #fff url("http://example.com/css_images/images/apple.png") 0 0 no-repeat;
|
4
|
-
}
|
5
|
-
|
6
|
-
/* relative */
|
7
|
-
div {
|
8
|
-
background: #fff url("/css_images/images/kiwi.jpg") 0 0 no-repeat;
|
9
|
-
}
|
10
|
-
|
11
|
-
/* relative root */
|
12
|
-
ul {
|
13
|
-
background: #fff url("../images/cantaloupe.png") 0 0 no-repeat;
|
14
|
-
}
|
15
|
-
|
16
|
-
/* import */
|
17
|
-
@import url("import_paths.css");
|
@@ -1,14 +0,0 @@
|
|
1
|
-
/* quotes */
|
2
|
-
dl {
|
3
|
-
background: #fff url("/css_images/images/apple.png") 0 0 no-repeat;
|
4
|
-
}
|
5
|
-
|
6
|
-
/* single quotes */
|
7
|
-
h1 {
|
8
|
-
background: #fff url('/css_images/images/kiwi.jpg') 0 0 no-repeat;
|
9
|
-
}
|
10
|
-
|
11
|
-
/* no quotes */
|
12
|
-
h2 {
|
13
|
-
background: #fff url(/css_images/images/cantaloupe.png) 0 0 no-repeat;
|
14
|
-
}
|
@@ -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="screen" type="text/css" />
|
11
|
-
</head>
|
12
|
-
<body>
|
13
|
-
<div></div>
|
14
|
-
</body>
|
15
|
-
</html>
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,12 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
color: #444;
|
3
|
-
background-color: #535353;
|
4
|
-
}
|
5
|
-
|
6
|
-
@import url("master.css");
|
7
|
-
@import url('/css_import/stylesheets/fonts.css');
|
8
|
-
@import url(http://example.com/css_import/stylesheets/ie.css);
|
9
|
-
@import url "images.css";
|
10
|
-
@import "borders.css";
|
11
|
-
@import colors.css;
|
12
|
-
@import url("invalid.css");
|
@@ -1,14 +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
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<img src="http://example.com/inline_images/images/apple.png" />
|
11
|
-
<p>Something</p>
|
12
|
-
<img src='http://example.com/inline_images/images/kiwi.jpg' />
|
13
|
-
</body>
|
14
|
-
</html>
|
Binary file
|
Binary file
|
@@ -1,14 +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
|
-
</head>
|
9
|
-
<body>
|
10
|
-
<img src="images/apple.png" />
|
11
|
-
<p>Something</p>
|
12
|
-
<img src='images/kiwi.jpg' />
|
13
|
-
</body>
|
14
|
-
</html>
|