color_parser 0.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +0 -2
- data/Guardfile +9 -0
- data/README.md +17 -26
- data/Rakefile +18 -6
- data/color_parser.gemspec +10 -2
- data/lib/color_parser.rb +3 -134
- data/lib/color_parser/errors.rb +3 -0
- data/lib/color_parser/page.rb +14 -57
- data/lib/color_parser/stylesheet.rb +27 -123
- data/lib/color_parser/version.rb +1 -1
- data/{test → spec}/fixtures/css_color/frequency.html +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/color_styles.css +7 -7
- data/{test → spec}/fixtures/css_color/stylesheets/css_elements.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/frequency.css +9 -9
- data/{test → spec}/fixtures/css_color/stylesheets/imported_selectors.css +0 -0
- data/{test → spec}/fixtures/css_color/stylesheets/properties.css +0 -0
- data/spec/page_spec.rb +39 -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 +125 -0
- data/spec/version_spec.rb +9 -0
- metadata +114 -123
- data/lib/color_parser/image.rb +0 -20
- data/test/color_parser_test.rb +0 -83
- data/test/fixtures/css/absolute.html +0 -15
- data/test/fixtures/css/inline.html +0 -34
- data/test/fixtures/css/inline_import.html +0 -16
- data/test/fixtures/css/invalid.html +0 -15
- data/test/fixtures/css/relative.html +0 -15
- data/test/fixtures/css/relative_root.html +0 -15
- data/test/fixtures/css/stylesheets/colors.css +0 -0
- data/test/fixtures/css/stylesheets/fonts.css +0 -0
- data/test/fixtures/css/stylesheets/print.css +0 -3
- data/test/fixtures/css/stylesheets/screen.css +0 -16
- data/test/fixtures/css_images/images/apple.png +0 -0
- data/test/fixtures/css_images/images/cantaloupe.png +0 -0
- data/test/fixtures/css_images/images/kiwi.jpg +0 -0
- data/test/fixtures/css_images/images/mango.png +0 -0
- data/test/fixtures/css_images/images/pineapple.png +0 -0
- data/test/fixtures/css_images/paths.html +0 -14
- data/test/fixtures/css_images/stylesheets/import_paths.css +0 -4
- data/test/fixtures/css_images/stylesheets/paths.css +0 -17
- data/test/fixtures/css_images/stylesheets/quotes.css +0 -14
- data/test/fixtures/css_import/index.html +0 -15
- data/test/fixtures/css_import/stylesheets/borders.css +0 -0
- data/test/fixtures/css_import/stylesheets/colors.css +0 -0
- data/test/fixtures/css_import/stylesheets/fonts.css +0 -3
- data/test/fixtures/css_import/stylesheets/ie.css +0 -3
- data/test/fixtures/css_import/stylesheets/images.css +0 -0
- data/test/fixtures/css_import/stylesheets/master.css +0 -12
- data/test/fixtures/css_import/stylesheets/print.css +0 -3
- data/test/fixtures/css_import/stylesheets/screen.css +0 -12
- data/test/fixtures/inline_images/absolute.html +0 -14
- data/test/fixtures/inline_images/images/apple.png +0 -0
- data/test/fixtures/inline_images/images/kiwi.jpg +0 -0
- data/test/fixtures/inline_images/relative.html +0 -14
- data/test/fixtures/inline_images/relative_root.html +0 -14
- data/test/image_test.rb +0 -27
- data/test/page_test.rb +0 -194
- data/test/stylesheet_test.rb +0 -257
- data/test/test_helper.rb +0 -6
- data/test/version_test.rb +0 -7
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/test/color_parser_test.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
describe ColorParser do
|
4
|
-
def setup
|
5
|
-
ColorParser.request = ColorParser::TestRequest.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
|
-
result.wont_be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
# parse_url
|
16
|
-
|
17
|
-
it "should parse url" do
|
18
|
-
url = "http://example.com/test/something/"
|
19
|
-
assert_equal ["example.com", "/test/something/", nil], ColorParser.parse_url(url)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should parse url with no trailing slash" do
|
23
|
-
|
24
|
-
url = "http://example.com"
|
25
|
-
assert_equal ["example.com", "/", nil], ColorParser.parse_url(url)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should parse url with query params" do
|
29
|
-
url = "http://example.com?foo=bar&baz=bar"
|
30
|
-
assert_equal ["example.com", "/", "foo=bar&baz=bar"], ColorParser.parse_url(url)
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
# parse_asset
|
35
|
-
|
36
|
-
it "should parse asset absolute path" do
|
37
|
-
doc = "http://example.com/stylesheets/base.css"
|
38
|
-
asset = "http://asset.example.com/stylesheets/style.css"
|
39
|
-
|
40
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
41
|
-
parsed.must_equal "http://asset.example.com/stylesheets/style.css"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should parse asset absolute path with query string" do
|
45
|
-
doc = "http://example.com/stylesheets/base.css?foo=bar"
|
46
|
-
asset = "http://asset.example.com/stylesheets/style.css?baz=bar"
|
47
|
-
|
48
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
49
|
-
parsed.must_equal "http://asset.example.com/stylesheets/style.css?baz=bar"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should parse relative root path" do
|
53
|
-
doc = "http://example.com/stylesheets/base.css"
|
54
|
-
asset = "/styles/style.css"
|
55
|
-
|
56
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
57
|
-
parsed.must_equal "http://example.com/styles/style.css"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should parse relative root path with query string" do
|
61
|
-
doc = "http://example.com/stylesheets/base.css?foo=bar"
|
62
|
-
asset = "/styles/style.css?baz=bar"
|
63
|
-
|
64
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
65
|
-
parsed.must_equal "http://example.com/styles/style.css?baz=bar"
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should parse relative path" do
|
69
|
-
doc = "http://example.com/stylesheets/base.css"
|
70
|
-
asset = "ie.css"
|
71
|
-
|
72
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
73
|
-
parsed.must_equal "http://example.com/stylesheets/ie.css"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should parse relative path with query string" do
|
77
|
-
doc = "http://example.com/stylesheets/base.css?foo=bar"
|
78
|
-
asset = "ie.css?baz=bar"
|
79
|
-
|
80
|
-
parsed = ColorParser.parse_asset(doc, asset)
|
81
|
-
parsed.must_equal "http://example.com/stylesheets/ie.css?baz=bar"
|
82
|
-
end
|
83
|
-
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
|
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>
|
@@ -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="/inline_images/images/apple.png" />
|
11
|
-
<p>Something</p>
|
12
|
-
<img src='/inline_images/images/kiwi.jpg' />
|
13
|
-
</body>
|
14
|
-
</html>
|
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
|