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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +0 -2
  4. data/Guardfile +9 -0
  5. data/README.md +17 -26
  6. data/Rakefile +18 -6
  7. data/color_parser.gemspec +10 -2
  8. data/lib/color_parser.rb +3 -134
  9. data/lib/color_parser/errors.rb +3 -0
  10. data/lib/color_parser/page.rb +14 -57
  11. data/lib/color_parser/stylesheet.rb +27 -123
  12. data/lib/color_parser/version.rb +1 -1
  13. data/{test → spec}/fixtures/css_color/frequency.html +0 -0
  14. data/{test → spec}/fixtures/css_color/stylesheets/color_styles.css +7 -7
  15. data/{test → spec}/fixtures/css_color/stylesheets/css_elements.css +0 -0
  16. data/{test → spec}/fixtures/css_color/stylesheets/frequency.css +9 -9
  17. data/{test → spec}/fixtures/css_color/stylesheets/imported_selectors.css +0 -0
  18. data/{test → spec}/fixtures/css_color/stylesheets/properties.css +0 -0
  19. data/spec/page_spec.rb +39 -0
  20. data/spec/spec_helper.rb +10 -0
  21. data/{test/test_request.rb → spec/stubs/fake_request.rb} +2 -2
  22. data/spec/stylesheet_spec.rb +125 -0
  23. data/spec/version_spec.rb +9 -0
  24. metadata +114 -123
  25. data/lib/color_parser/image.rb +0 -20
  26. data/test/color_parser_test.rb +0 -83
  27. data/test/fixtures/css/absolute.html +0 -15
  28. data/test/fixtures/css/inline.html +0 -34
  29. data/test/fixtures/css/inline_import.html +0 -16
  30. data/test/fixtures/css/invalid.html +0 -15
  31. data/test/fixtures/css/relative.html +0 -15
  32. data/test/fixtures/css/relative_root.html +0 -15
  33. data/test/fixtures/css/stylesheets/colors.css +0 -0
  34. data/test/fixtures/css/stylesheets/fonts.css +0 -0
  35. data/test/fixtures/css/stylesheets/print.css +0 -3
  36. data/test/fixtures/css/stylesheets/screen.css +0 -16
  37. data/test/fixtures/css_images/images/apple.png +0 -0
  38. data/test/fixtures/css_images/images/cantaloupe.png +0 -0
  39. data/test/fixtures/css_images/images/kiwi.jpg +0 -0
  40. data/test/fixtures/css_images/images/mango.png +0 -0
  41. data/test/fixtures/css_images/images/pineapple.png +0 -0
  42. data/test/fixtures/css_images/paths.html +0 -14
  43. data/test/fixtures/css_images/stylesheets/import_paths.css +0 -4
  44. data/test/fixtures/css_images/stylesheets/paths.css +0 -17
  45. data/test/fixtures/css_images/stylesheets/quotes.css +0 -14
  46. data/test/fixtures/css_import/index.html +0 -15
  47. data/test/fixtures/css_import/stylesheets/borders.css +0 -0
  48. data/test/fixtures/css_import/stylesheets/colors.css +0 -0
  49. data/test/fixtures/css_import/stylesheets/fonts.css +0 -3
  50. data/test/fixtures/css_import/stylesheets/ie.css +0 -3
  51. data/test/fixtures/css_import/stylesheets/images.css +0 -0
  52. data/test/fixtures/css_import/stylesheets/master.css +0 -12
  53. data/test/fixtures/css_import/stylesheets/print.css +0 -3
  54. data/test/fixtures/css_import/stylesheets/screen.css +0 -12
  55. data/test/fixtures/inline_images/absolute.html +0 -14
  56. data/test/fixtures/inline_images/images/apple.png +0 -0
  57. data/test/fixtures/inline_images/images/kiwi.jpg +0 -0
  58. data/test/fixtures/inline_images/relative.html +0 -14
  59. data/test/fixtures/inline_images/relative_root.html +0 -14
  60. data/test/image_test.rb +0 -27
  61. data/test/page_test.rb +0 -194
  62. data/test/stylesheet_test.rb +0 -257
  63. data/test/test_helper.rb +0 -6
  64. data/test/version_test.rb +0 -7
@@ -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,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
@@ -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
- }
@@ -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,4 +0,0 @@
1
- /* imported */
2
- h2 {
3
- background: #fff url("/css_images/images/pineapple.png") 0 0 no-repeat;
4
- }
@@ -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>
@@ -1,3 +0,0 @@
1
- body {
2
- font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Arial, sans-serif;
3
- }
@@ -1,3 +0,0 @@
1
- div {
2
- background-color: red;
3
- }
@@ -1,12 +0,0 @@
1
- a:link {
2
- color: #357ad1;
3
- }
4
- a:visited {
5
- color: #77abf0;
6
- }
7
- a:hover {
8
- color: #333;
9
- }
10
- .shade {
11
- background-color: #f5f5f5;
12
- }
@@ -1,3 +0,0 @@
1
- body {
2
- margin: 0;
3
- }
@@ -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>
@@ -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>
@@ -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