ruby_color_contrast_checker 0.1.0 → 0.2.0
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 +4 -4
- data/Gemfile +6 -0
- data/Gemfile.lock +9 -5
- data/README.md +112 -14
- data/assets/color_contrast_checker_cli.png +0 -0
- data/lib/ruby_color_contrast_checker/version.rb +1 -1
- data/lib/ruby_color_contrast_checker.rb +52 -9
- data/ruby_color_contrast_checker.gemspec +0 -5
- metadata +3 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40345e8b055888a53d71039c61513b0d6db1dd83acdf35657921bc9a303eed9f
|
4
|
+
data.tar.gz: 47be0542a7799e2b788596e395ac989fddee8035bb66561c61cea513a298c157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb1724ffe3dab3f991e1a896c83282b5cb997be99faecd2eaa27ec814f38417d75bd1166113e50333e351eaa76544bc315762dbacefbe588c3d55047150878f
|
7
|
+
data.tar.gz: 1c340332128989b61e3a4460d052597664e8ec46389c5d259ee01c4e88e71435b5aa713a89dad184e49a36e5fae431937aa0786f6fd8619ae33fd990949e8cea
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby_color_contrast_checker (0.
|
4
|
+
ruby_color_contrast_checker (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -52,6 +52,9 @@ GEM
|
|
52
52
|
docile (~> 1.1)
|
53
53
|
simplecov-html (~> 0.11)
|
54
54
|
simplecov_json_formatter (~> 0.1)
|
55
|
+
simplecov-cobertura (2.1.0)
|
56
|
+
rexml
|
57
|
+
simplecov (~> 0.19)
|
55
58
|
simplecov-html (0.12.3)
|
56
59
|
simplecov_json_formatter (0.1.4)
|
57
60
|
standard (1.28.4)
|
@@ -71,11 +74,12 @@ PLATFORMS
|
|
71
74
|
x86_64-linux
|
72
75
|
|
73
76
|
DEPENDENCIES
|
74
|
-
rake
|
75
|
-
rspec
|
77
|
+
rake
|
78
|
+
rspec
|
76
79
|
ruby_color_contrast_checker!
|
77
|
-
simplecov
|
78
|
-
|
80
|
+
simplecov
|
81
|
+
simplecov-cobertura
|
82
|
+
standard
|
79
83
|
|
80
84
|
BUNDLED WITH
|
81
85
|
2.4.7
|
data/README.md
CHANGED
@@ -1,39 +1,137 @@
|
|
1
|
-
|
1
|
+
<div align="center">
|
2
|
+
<h1 align="center">Ruby Color Contrast Checker</h1>
|
3
|
+
<p align="center">CLI interface for checking WCAG2.0 Color Contrast Ratio in Ruby.</p>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<br />
|
7
|
+
|
8
|
+
<div align="center">
|
9
|
+
<a href="https://badge.fury.io/rb/ruby_color_contrast_checker">
|
10
|
+
<img alt="Gem Version" src="https://badge.fury.io/rb/ruby_color_contrast_checker.svg" />
|
11
|
+
</a>
|
12
|
+
|
13
|
+
<a href="https://github.com/cheehwatang/ruby_color_contrast_checker/blob/main/LICENSE.txt">
|
14
|
+
<img alt="GitHub license" src="https://img.shields.io/github/license/cheehwatang/ruby_color_contrast_checker" />
|
15
|
+
</a>
|
16
|
+
|
17
|
+
<a href="#">
|
18
|
+
<img alt="Tests Passing" src="https://github.com/cheehwatang/ruby_color_contrast_checker/workflows/Test/badge.svg" />
|
19
|
+
</a>
|
20
|
+
|
21
|
+
<a href="#">
|
22
|
+
<img alt="Lint Passing" src="https://github.com/cheehwatang/ruby_color_contrast_checker/workflows/Lint/badge.svg" />
|
23
|
+
</a>
|
24
|
+
|
25
|
+
<a href="#">
|
26
|
+
<img alt="Code Coverage Percentage" src="https://codecov.io/gh/cheehwatang/ruby_color_contrast_checker/branch/master/graph/badge.svg" />
|
27
|
+
</a>
|
28
|
+
|
29
|
+
<a href="https://github.com/standardrb/standard">
|
30
|
+
<img alt="Ruby Code Style" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" />
|
31
|
+
</a>
|
32
|
+
|
33
|
+
<a href="#">
|
34
|
+
<img alt="Repository Top Language" src="https://img.shields.io/github/languages/top/cheehwatang/ruby_color_contrast_checker" />
|
35
|
+
</a>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<br />
|
39
|
+
|
40
|
+
<hr />
|
41
|
+
|
42
|
+
<br />
|
43
|
+
|
44
|
+
Check if the 2 colors provided pass the AA and AAA Levels (including for Large Text and Icons), according to [WCAG 2.1 guidelines](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).
|
45
|
+
|
46
|
+
Further information can be found [here](https://webaim.org/articles/contrast/).
|
47
|
+
|
48
|
+
In summary:
|
49
|
+
|
50
|
+
- Level AA : Ratio > 4.5
|
51
|
+
- Level AA (Large) : Ratio > 3.0
|
52
|
+
- Level AAA : Ratio > 7.0
|
53
|
+
- Level AAA (Large) : Ratio > 4.5
|
54
|
+
|
55
|
+
Note:
|
56
|
+
|
57
|
+
Large is for regular text with 18pt or larger, or bold text with 14pt or larger.
|
58
|
+
|
59
|
+
Logo generally fall into the large category.
|
60
|
+
|
61
|
+
It is recommended to fulfill at least Level AA for your projects.
|
62
|
+
|
63
|
+
<br />
|
2
64
|
|
3
|
-
|
65
|
+
## Installation
|
4
66
|
|
5
|
-
|
67
|
+
Install the gem:
|
6
68
|
|
7
|
-
|
69
|
+
```console
|
70
|
+
$ gem install ruby_color_contrast_checker
|
71
|
+
```
|
8
72
|
|
9
|
-
|
73
|
+
<br />
|
10
74
|
|
11
|
-
|
75
|
+
## Usage
|
12
76
|
|
13
|
-
|
77
|
+
Run the `contrast_checker` executable:
|
14
78
|
|
15
|
-
|
79
|
+
```shell
|
80
|
+
$ contrast_checker
|
16
81
|
|
17
|
-
|
82
|
+
------------------------------------
|
83
|
+
| Welcome to Color Contrast Checker |
|
84
|
+
------------------------------------
|
85
|
+
\ ^__^
|
86
|
+
\ (oo)_______
|
87
|
+
(__)\ )\/\
|
88
|
+
||----w |
|
89
|
+
|| ||
|
18
90
|
|
19
|
-
|
91
|
+
Enter the first hex color string:
|
92
|
+
> #000000
|
93
|
+
Enter the second hex color string:
|
94
|
+
> #FFFFFF
|
95
|
+
|
96
|
+
Contrast Ratio : 21
|
97
|
+
|
98
|
+
Level AA : PASS
|
99
|
+
Level AA (Large) : PASS
|
100
|
+
Level AAA : PASS
|
101
|
+
Level AAA (Large) : PASS
|
102
|
+
```
|
103
|
+
|
104
|
+

|
20
105
|
|
21
|
-
|
106
|
+
<br />
|
22
107
|
|
23
108
|
## Development
|
24
109
|
|
25
110
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
111
|
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
112
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
113
|
+
|
114
|
+
<br />
|
28
115
|
|
29
116
|
## Contributing
|
30
117
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cheehwatang/ruby_color_contrast_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cheehwatang/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
|
119
|
+
|
120
|
+
<br />
|
32
121
|
|
33
122
|
## License
|
34
123
|
|
35
124
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
125
|
|
126
|
+
<br />
|
127
|
+
|
37
128
|
## Code of Conduct
|
38
129
|
|
39
|
-
Everyone interacting in the
|
130
|
+
Everyone interacting in the Ruby Color Contrast Checker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cheehwatang/ruby_color_contrast_checker/blob/master/CODE_OF_CONDUCT.md).
|
131
|
+
|
132
|
+
<br />
|
133
|
+
|
134
|
+
## 🌟 Special Thanks
|
135
|
+
|
136
|
+
- [WebAIM Contrast Checker API](https://webaim.org/resources/contrastchecker/) for the contrast checker API.
|
137
|
+
- [Richard Bates](https://github.com/richo225) for the [blog post](https://richardbates.dev/blog/2023-05-05) on releasing a gem.
|
Binary file
|
@@ -34,35 +34,78 @@ module RubyColorContrastChecker
|
|
34
34
|
gets.chomp
|
35
35
|
end
|
36
36
|
|
37
|
+
def red(string)
|
38
|
+
"\e[31m#{string}\e[0m"
|
39
|
+
end
|
40
|
+
|
41
|
+
def green(string)
|
42
|
+
"\e[32m#{string}\e[0m"
|
43
|
+
end
|
44
|
+
|
45
|
+
def colorize_float(float_string)
|
46
|
+
return red(float_string) if Float(float_string) < 4.5
|
47
|
+
|
48
|
+
green(float_string)
|
49
|
+
end
|
50
|
+
|
51
|
+
def colorize_status(status_string)
|
52
|
+
status_string = status_string.upcase
|
53
|
+
|
54
|
+
return red(status_string) if status_string == "FAIL"
|
55
|
+
|
56
|
+
green(status_string)
|
57
|
+
end
|
58
|
+
|
37
59
|
def print_data(data)
|
38
60
|
output = <<~MLS
|
39
|
-
|
61
|
+
\e[36mContrast Ratio\e[0m : #{colorize_float(data["ratio"])}
|
40
62
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
63
|
+
\e[36mLevel AA\e[0m : #{colorize_status(data["AA"])}
|
64
|
+
\e[36mLevel AA (Large)\e[0m : #{colorize_status(data["AALarge"])}
|
65
|
+
\e[36mLevel AAA\e[0m : #{colorize_status(data["AAA"])}
|
66
|
+
\e[36mLevel AAA (Large)\e[0m : #{colorize_status(data["AAALarge"])}
|
45
67
|
MLS
|
46
68
|
|
47
69
|
puts output
|
48
70
|
end
|
49
71
|
|
72
|
+
def print_welcome_message
|
73
|
+
welcome_message = <<~MLS
|
74
|
+
\e[36m ------------------------------------ \e[0m
|
75
|
+
\e[36m | Welcome to Color Contrast Checker | \e[0m
|
76
|
+
\e[36m ------------------------------------ \e[0m
|
77
|
+
\\ ^__^
|
78
|
+
\\ (oo)_______
|
79
|
+
(__)\\ )\\/\\
|
80
|
+
||----w |
|
81
|
+
|| ||
|
82
|
+
MLS
|
83
|
+
|
84
|
+
puts welcome_message
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_error_message
|
88
|
+
puts "\e[31mThe Hex color code is invalid.\e[0m"
|
89
|
+
end
|
90
|
+
|
50
91
|
def run
|
92
|
+
print_welcome_message
|
93
|
+
|
51
94
|
loop do
|
52
95
|
puts
|
53
|
-
first = prompt_input("
|
54
|
-
second = prompt_input("
|
96
|
+
first = prompt_input("\e[36mEnter the first hex color string:\e[0m \n\e[30m> #\e[0m")
|
97
|
+
second = prompt_input("\e[36mEnter the second hex color string:\e[0m \n\e[30m> #\e[0m")
|
55
98
|
puts
|
56
99
|
|
57
100
|
if !valid_hex?(first) || !valid_hex?(second)
|
58
|
-
|
101
|
+
print_error_message
|
59
102
|
else
|
60
103
|
data = fetch_data(first, second)
|
61
104
|
print_data(data)
|
62
105
|
end
|
63
106
|
|
64
107
|
puts
|
65
|
-
input = prompt_input("
|
108
|
+
input = prompt_input("\e[33mContinue?\e[0m (\e[32myes\e[0m / \e[31mno\e[0m) ")
|
66
109
|
break if input.downcase == "no"
|
67
110
|
end
|
68
111
|
end
|
@@ -29,9 +29,4 @@ Gem::Specification.new do |spec|
|
|
29
29
|
end
|
30
30
|
spec.executables = ["contrast_checker"]
|
31
31
|
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
34
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
-
spec.add_development_dependency "standard", "~> 1.3"
|
36
|
-
spec.add_development_dependency "simplecov", "~> 0.21.2"
|
37
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_color_contrast_checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chee Hwa Tang
|
@@ -9,63 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-05-30 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '13.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '13.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: standard
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.3'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: simplecov
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.21.2
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.21.2
|
12
|
+
dependencies: []
|
69
13
|
description: 'CLI interface for WCAG Color Contrast Checking in Ruby '
|
70
14
|
email:
|
71
15
|
- cheehwa.tang@gmail.com
|
@@ -83,6 +27,7 @@ files:
|
|
83
27
|
- LICENSE.txt
|
84
28
|
- README.md
|
85
29
|
- Rakefile
|
30
|
+
- assets/color_contrast_checker_cli.png
|
86
31
|
- bin/contrast_checker
|
87
32
|
- lib/ruby_color_contrast_checker.rb
|
88
33
|
- lib/ruby_color_contrast_checker/version.rb
|