-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.erb
287 lines (258 loc) · 10.9 KB
/
template.erb
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<%
require 'yaml'
require 'ostruct'
require 'json'
# Collect paths
colorscheme_files = Dir['schemes/base16/*.yaml']
# Parse each file into an OpenStruct object, including the slug
colorschemes = colorscheme_files.map do |file_path|
slug = File.basename(file_path, '.yaml')
data = YAML.load_file(file_path)
data['slug'] ||= slug
OpenStruct.new(data)
end
%>
<!doctype html>
<html lang="en">
<head>
<title>Base16 Gallery</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
<% colorschemes.each do |colorscheme| %>
<%= File.read("out/#{colorscheme.slug}.css") %>
<% end %>
</style>
<style>
h1 {
font-family: Lobster, cursive;
}
.Scheme-codeBlock::-webkit-scrollbar,
.Scheme-meta::-webkit-scrollbar {
display: none;
}
.Scheme-codeBlock,
.Scheme-meta {
scrollbar-width: none;
padding: 20px;
height: 300px;
overflow-y: scroll;
box-shadow: 5px 5px 10px #333;
border-radius: 5px;
}
.Scheme-codeBlock a {
color: inherit;
text-decoration: none;
pointer-events: none;
}
.Scheme-title {
font-size: 1.5em !important;
padding-bottom: 50px;
}
.Scheme-palette {
justify-content: center;
display: flex;
box-shadow: 5px 5px 10px #333;
}
.Scheme-color {
flex-grow: 1;
height: 30px;
}
.Scheme-content {
position: relative;
}
.Scheme-checkbox {
top: 10px;
right: 10px;
position: absolute;
}
.Scheme-checkbox:not(:checked) + pre {
display: none;
}
.Scheme-checkbox:checked + pre + pre {
display: none;
}
.darkmode {
background-color: #333;
color: #fff;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<h1 class="text-center">Base16 Gallery</h1>
<p class="text-center">
This gallery is generated from <a href="https://github.com/tinted-theming/tinted-vim">tinted-theming/tinted-vim</a>.</p>
</div>
<div>
Group by variant: <input id="sort-by-variant" type="checkbox" />
</div>
<div>
Dark mode: <input id="darkmode" type="checkbox" />
</div>
<div class="row" id="gallery">
<% colorschemes.each do |cs| %>
<div class="Scheme col-xxl-2 col-lg-3 col-md-4 col-sm-6" id="base16-<%= cs.slug %>" data-scheme-variant="<%= cs.variant %>">
<div class="Scheme-content">
<input class="Scheme-checkbox" type="checkbox" />
<pre class="Scheme-meta"><code><%= File.read("schemes/base16/#{cs.slug}.yaml") %></code></pre>
<pre class="Scheme-codeBlock"><code> <%= File.read("out/shell.html") %> </code></pre>
</div>
<div class="Scheme-palette">
<div class="Scheme-color" title="<%= cs.palette['base00'] %>" style="background-color: <%= cs.palette['base00'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base01'] %>" style="background-color: <%= cs.palette['base01'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base02'] %>" style="background-color: <%= cs.palette['base02'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base03'] %>" style="background-color: <%= cs.palette['base03'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base04'] %>" style="background-color: <%= cs.palette['base04'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base05'] %>" style="background-color: <%= cs.palette['base05'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base06'] %>" style="background-color: <%= cs.palette['base06'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base07'] %>" style="background-color: <%= cs.palette['base07'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base08'] %>" style="background-color: <%= cs.palette['base08'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base09'] %>" style="background-color: <%= cs.palette['base09'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0A'] %>" style="background-color: <%= cs.palette['base0A'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0B'] %>" style="background-color: <%= cs.palette['base0B'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0C'] %>" style="background-color: <%= cs.palette['base0C'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0D'] %>" style="background-color: <%= cs.palette['base0D'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0E'] %>" style="background-color: <%= cs.palette['base0E'] %>"></div>
<div class="Scheme-color" title="<%= cs.palette['base0F'] %>" style="background-color: <%= cs.palette['base0F'] %>"></div>
</div>
<div class="Scheme-title text-center">
<%= cs.slug %>
</div>
</div>
<% end %>
</div>
</div>
<script>
const colorschemes = <%= colorschemes.map(&:to_h).to_json %>;
const galleryEl = document.getElementById('gallery');
const codeText = {
shell: <%= File.read('out/shell.html').to_json %>
};
// Listen for changes to DOM "settings" and re-render
document.getElementById('sort-by-variant').addEventListener('change', function() {
renderSchemes();
});
// Toggle dark mode
document.getElementById('darkmode').addEventListener('change', function() {
const checkbox = document.getElementById('darkmode');
const isChecked = checkbox.checked; // Returns true if checked, false if not
if (isChecked) {
document.body.classList.add('darkmode');
} else {
document.body.classList.remove('darkmode');
}
});
// Get settings from DOM
function getSettings() {
const groupBy = [];
const isGroupedByVariant = document.getElementById('sort-by-variant').checked;
if (isGroupedByVariant) {
groupBy.push('variant');
}
return {
groupBy,
}
}
// Render all schemes to the DOM
function renderSchemes() {
const { groupBy } = getSettings();
const schemes = [...colorschemes];
emptyGalleryEl();
if (groupBy.includes('variant')) {
schemes.sort((a, b) => {
if (a.variant < b.variant) return 1;
if (a.variant > b.variant) return -1;
return 0;
});
}
for (let i = 0; i < schemes.length; i++) {
const colorscheme = schemes[i];
appendSchemeToGalleryEl(colorscheme);
}
}
// Clear gallery DOM contents
function emptyGalleryEl() {
while (gallery.firstChild) {
gallery.removeChild(gallery.firstChild);
}
}
// Add individual Scheme element to DOM
function appendSchemeToGalleryEl(cs) {
const schemeDiv = document.createElement('div');
schemeDiv.className = 'Scheme col-xxl-2 col-lg-3 col-md-4 col-sm-6 heh';
schemeDiv.id = `base16-${cs.slug}`;
schemeDiv.setAttribute('data-scheme-variant', cs.variant);
// Create Scheme-content div
const schemeContentDiv = document.createElement('div');
schemeContentDiv.className = 'Scheme-content';
// Add checkbox input
const checkbox = document.createElement('input');
checkbox.className = 'Scheme-checkbox';
checkbox.type = 'checkbox';
schemeContentDiv.appendChild(checkbox);
// Add Scheme-meta pre/code
const schemeMetaPre = document.createElement('pre');
schemeMetaPre.className = 'Scheme-meta';
const schemeMetaCode = document.createElement('code');
schemeMetaCode.textContent = `system: ${cs.system}
slug: ${cs.slug}
name: ${cs.name}
author: ${cs.author}
variant: ${cs.variant}
palette:
${cs.palette.base00 ? 'base00: ' + cs.palette.base00 : ''}
${cs.palette.base01 ? 'base01: ' + cs.palette.base01 : ''}
${cs.palette.base02 ? 'base02: ' + cs.palette.base02 : ''}
${cs.palette.base03 ? 'base03: ' + cs.palette.base03 : ''}
${cs.palette.base04 ? 'base04: ' + cs.palette.base04 : ''}
${cs.palette.base05 ? 'base05: ' + cs.palette.base05 : ''}
${cs.palette.base06 ? 'base06: ' + cs.palette.base06 : ''}
${cs.palette.base07 ? 'base07: ' + cs.palette.base07 : ''}
${cs.palette.base08 ? 'base08: ' + cs.palette.base08 : ''}
${cs.palette.base09 ? 'base09: ' + cs.palette.base09 : ''}
${cs.palette.base0A ? 'base0A: ' + cs.palette.base0A : ''}
${cs.palette.base0B ? 'base0B: ' + cs.palette.base0B : ''}
${cs.palette.base0C ? 'base0C: ' + cs.palette.base0C : ''}
${cs.palette.base0D ? 'base0D: ' + cs.palette.base0D : ''}
${cs.palette.base0E ? 'base0E: ' + cs.palette.base0E : ''}
${cs.palette.base0F ? 'base0F: ' + cs.palette.base0F : ''}`
schemeMetaPre.appendChild(schemeMetaCode);
schemeContentDiv.appendChild(schemeMetaPre);
// Add Scheme-codeBlock pre/code
const schemeCodeBlockPre = document.createElement('pre');
schemeCodeBlockPre.className = 'Scheme-codeBlock';
const schemeCodeBlockCode = document.createElement('code');
schemeCodeBlockCode.innerHTML = codeText.shell;
schemeCodeBlockPre.appendChild(schemeCodeBlockCode);
schemeContentDiv.appendChild(schemeCodeBlockPre);
// Append Scheme-content to the main div
schemeDiv.appendChild(schemeContentDiv);
// Create Scheme-palette div
const schemePaletteDiv = document.createElement('div');
schemePaletteDiv.className = 'Scheme-palette';
// Add Scheme-color divs for the palette
Object.entries(cs.palette).forEach(([key, color]) => {
const colorDiv = document.createElement('div');
colorDiv.className = 'Scheme-color';
colorDiv.title = color;
colorDiv.style.backgroundColor = color;
schemePaletteDiv.appendChild(colorDiv);
});
// Append Scheme-palette to the main div
schemeDiv.appendChild(schemePaletteDiv);
// Create Scheme-title div
const schemeTitleDiv = document.createElement('div');
schemeTitleDiv.className = 'Scheme-title text-center';
schemeTitleDiv.textContent = cs.slug;
// Append Scheme-title to the main div
schemeDiv.appendChild(schemeTitleDiv);
// Append the entire structure to the document (or another container)
galleryEl.appendChild(schemeDiv);
}
</script>
</body>
</html>