-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmix.exs
173 lines (141 loc) · 4.43 KB
/
mix.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
defmodule Colorex.MixProject do
use Mix.Project
def project do
[
app: :colorex,
version: "1.0.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
description: description(),
name: "Colorex",
source_url: "https://github.com/pejrich/colorex",
docs: &docs/0,
aliases: aliases()
]
end
def docs do
[
# The main page in the docs
main: "Colorex",
extras: ["README.md", "NamedColors.md"],
before_closing_body_tag: &before_closing_body_tag/1,
source_ref: "master"
]
end
def description, do: "A library for working with colors. Mixing, comparing, adjusting and more."
def package do
[
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/pejrich/colorex"}
]
end
def before_closing_body_tag(_) do
"""
<script>
window.onload = function() {
console.log("load called");
Array.from(document.querySelectorAll("code.makeup span")).forEach((elem) => {
elem.innerHTML = elem.innerHTML.replace(/rgba?[(].*?[)]/g, (i,j,k) => {
return `<span style='background-color: ${i};'>${i}</span>`;
})
elem.innerHTML = elem.innerHTML.replace(/hsla?[(].*?[)]/g, (i,j,k) => {
return `<span style='background-color: ${i};'>${i}</span>`;
})
elem.innerHTML = elem.innerHTML.replace(/\#[A-Fa-f0-9]{3,8}/g, (i) => `<span style='background-color: ${i};'>${i}</span>`);
})
}
</script>
"""
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: extra_applications(Mix.env())
]
end
defp extra_applications(:dev),
do: [:wx, :syntax_tools, :logger, :runtime_tools, :tools, :observer]
defp extra_applications(_), do: [:logger]
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:jason, ">= 0.0.0"},
{:benchee, ">= 0.0.0", only: [:dev]},
{:ex_doc, ">= 0.0.0", only: [:dev], runtime: false}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
def aliases do
[docs: ["compile", &generate_named_colors/1, "docs", ©_images/1]]
end
defp copy_images(_) do
File.mkdir_p!("doc/images") |> IO.inspect()
Path.wildcard("images/*")
|> Enum.each(&File.cp!(&1, "doc/images/#{Path.basename(&1)}"))
end
defp generate_named_colors(_) do
Code.ensure_loaded?(Colorex)
colors = Colorex.Support.parse_tsv("priv/named_colors.tsv")
body =
colors
|> Enum.sort_by(fn [a | _] -> String.downcase(a) end)
|> Enum.map(fn [name, key, hex, source] ->
{Colorex.parse!(hex),
"<tr><td>#{name}</td><td><code>#{key}</code></td><td><code>#{hex}</code></td><td>#{source}</td><td style='background: #{hex};'></td></tr>"}
end)
az = Enum.map_join(body, &elem(&1, 1))
light_dark =
body
# |> tap(fn x -> Enum.take(x, 10) |> IO.inspect() end)
|> Enum.sort_by(fn {color, _} -> Colorex.shade_number(color) end)
# |> tap(fn x -> Enum.take(x, 10) |> IO.inspect() end)
|> Enum.map_join(&elem(&1, 1))
hue =
body
|> Enum.split_with(fn {color, _} -> Colorex.grayscale?(color, 3) end)
|> then(fn {gray, colors} ->
Enum.sort_by(colors, fn {color, _} ->
{round(Colorex.get(color, :hue) / 6) * 6, Colorex.shade_number(color)}
end)
|> Enum.concat(Enum.sort_by(gray, &Colorex.shade_number(elem(&1, 0))))
end)
|> Enum.map_join(&elem(&1, 1))
md = """
# Named Colors
### Below is a list of all #{length(colors)} named colors.
When using named colors with `Colorex.parse/1` or `Colorex.parse!/1` the text from the `Keyword` column is the value you want to use. It is always lowercase a-z letters.
<!-- tabs-open -->
### A-Z
#{wrap_table(az)}
### Hue
#{wrap_table(hue)}
### Dark - Light
#{wrap_table(light_dark)}
<!-- tabs-close -->
"""
File.write!("NamedColors.md", md)
end
defp wrap_table(body) do
"""
<div>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Keyword</th>
<th scope="col">RGB hex value</th>
<th scope="col">Source</th>
<th scope="col">Sample</th>
</tr>
</thead>
<tbody>
#{body}
</tbody>
</table>
</div>
"""
end
end