-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
262 lines (239 loc) · 9.18 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Helm Playground | Debug Helm templates in your browser</title>
<meta
name="description"
content="Live preview Helm charts in your browser."
/>
<link rel="stylesheet" href="codemirror/codemirror.css" />
<link rel="stylesheet" href="codemirror/material.css" />
<link rel="stylesheet" href="style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
<body>
<div class="app app--playground">
<div class="top">
<a class="logo" href="/">Helm-playground.com</a>
<a class="top__link" href="/cheatsheet.html"
>Syntax cheatsheet
<span
style="
background-color: #059669;
text-transform: uppercase;
font-weight: 600;
padding: 1px 4px;
border-radius: 4px;
font-size: 10px;
color: #ecfdf5;
"
>New</span
></a
>
<a
style="margin-left: auto"
class="top__link hide-on-mobile"
href="https://shipmight.com"
>Brought to you by Shipmight - Kubernetes-powered PaaS in your
cloud</a
>
</div>
<div class="content">
<div class="column">
<div class="label">template.yaml</div>
<textarea class="textarea textarea--template"></textarea>
</div>
<div class="column">
<div class="label">values.yaml</div>
<textarea class="textarea textarea--values"></textarea>
</div>
<div class="column">
<div class="label">output</div>
<textarea class="textarea textarea--output" readonly></textarea>
</div>
<div class="overlay">
<p><button class="start">Start playground</button></p>
<p><strong>Debug Helm templates in your browser</strong></p>
<p class="overlay__dim">
A WebAssembly-file (2.3MB gzipped) will be downloaded and cached by
your browser. It includes Sprig, which Helm uses for templating.
Source on
<a href="https://github.com/shipmight/helm-playground">GitHub</a>.
</p>
</div>
<div class="floating-error" style="display: none"></div>
<div class="floating-warning" style="display: none"></div>
</div>
</div>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/yaml.js"></script>
<script src="codemirror/placeholder.js"></script>
<script src="codemirror/cm-show-invisibles.js"></script>
<script src="lz-string.js"></script>
<script src="dist/wasm_exec.js"></script>
<script src="lib.js"></script>
<script>
const compress = LZString.compressToEncodedURIComponent;
const decompress = LZString.decompressFromEncodedURIComponent;
const updateHash = (templateValue, valuesValue) => {
const hashParams = new URLSearchParams();
hashParams.append("t", compress(templateValue));
hashParams.append("v", compress(valuesValue));
const hash = hashParams.toString();
window.history.replaceState(null, "", `#${hash}`);
};
const readHash = () => {
const hashContent = window.location.hash.slice(1);
if (hashContent === "") {
return;
}
const params = new URLSearchParams(hashContent);
const templateValue = decompress(params.get("t"));
const valuesValue = decompress(params.get("v"));
return { templateValue, valuesValue };
};
let defaultTemplateYaml =
"---\nexample: {{- .Values.items | toYaml | nindent 2 }}\n";
let defaultValuesYaml = '---\nitems: ["first", "second"]\n';
let defaultOutput = "---\nexample: \n - first\n - second\n";
const fromHash = readHash();
if (fromHash) {
defaultTemplateYaml = fromHash.templateValue;
defaultValuesYaml = fromHash.valuesValue;
defaultOutput = "";
}
const templateTextarea = document.querySelector(".textarea--template");
const valuesTextarea = document.querySelector(".textarea--values");
const outputTextarea = document.querySelector(".textarea--output");
templateTextarea.value = defaultTemplateYaml;
valuesTextarea.value = defaultValuesYaml;
outputTextarea.value = defaultOutput;
const codeMirrorOptions = {
mode: "yaml",
theme: "material",
showInvisibles: true,
// Source: https://github.com/codemirror/codemirror5/issues/988#issuecomment-549644684
tabSize: 2,
indentWithTabs: false,
smartIndent: true,
extraKeys: {
Tab: (cm) => {
if (cm.getMode().name === "null") {
cm.execCommand("insertTab");
} else {
if (cm.somethingSelected()) {
cm.execCommand("indentMore");
} else {
cm.execCommand("insertSoftTab");
}
}
},
"Shift-Tab": (cm) => cm.execCommand("indentLess"),
},
};
const templateCodeMirror = CodeMirror.fromTextArea(templateTextarea, {
...codeMirrorOptions,
placeholder: "Copy your Helm template here",
});
const valuesCodeMirror = CodeMirror.fromTextArea(valuesTextarea, {
...codeMirrorOptions,
placeholder: "Copy your values YAML here",
});
const outputCodeMirror = CodeMirror.fromTextArea(outputTextarea, {
...codeMirrorOptions,
placeholder: "Generated output will show up here",
});
templateTextarea.CodeMirror = templateCodeMirror;
valuesTextarea.CodeMirror = valuesCodeMirror;
outputTextarea.CodeMirror = outputCodeMirror;
const overlay = document.querySelector(".overlay");
const startButton = document.querySelector(".start");
const errorNotification = document.querySelector(".floating-error");
const warningNotification = document.querySelector(".floating-warning");
const formatError = (err) => {
err = err.replace("template: ", "template.yaml - ");
err = err.replace("yaml: ", "values.yaml - ");
return err;
};
const parseTemplateError = (err) => {
if (err.startsWith("template: ")) {
const match = err.match(/template:([0-9]+)(?::([0-9]+))?/);
if (match) {
let [, lineNum, characterNum] = match;
if (characterNum === undefined) {
return { lineNum: parseInt(lineNum) - 1 };
}
return {
lineNum: parseInt(lineNum) - 1,
characterNum: parseInt(characterNum),
};
}
}
};
startButton.addEventListener("click", () => {
startButton.disabled = true;
startButton.textContent = "Loading…";
window
.loadGetYaml()
.then((getYaml) => {
overlay.style.display = "none";
const markers = new Set();
const onChange = () => {
const templateValue = templateCodeMirror.getValue();
const valuesValue = valuesCodeMirror.getValue();
const { yaml, err, warning } = getYaml(
templateValue,
valuesValue
);
for (const marker of markers.values()) {
marker.clear();
markers.delete(marker);
}
errorNotification.style.display = "none";
warningNotification.style.display = "none";
if (err) {
const templateError = parseTemplateError(err);
if (templateError) {
const { lineNum, characterNum } = templateError;
const start =
typeof characterNum === "undefined" ? 0 : characterNum;
const end =
typeof characterNum === "undefined"
? 1000
: characterNum + 1;
const marker = templateCodeMirror.markText(
{ line: lineNum, ch: start },
{ line: lineNum, ch: end },
{ className: "marker-error" }
);
markers.add(marker);
}
errorNotification.style.display = "block";
errorNotification.textContent = formatError(err);
} else {
outputCodeMirror.setValue(yaml);
if (warning) {
warningNotification.style.display = "block";
warningNotification.textContent = `Warning, the generated YAML may contain parsing errors. Converting it to JSON failed: ${warning}`;
}
}
updateHash(templateValue, valuesValue);
};
templateCodeMirror.on("change", onChange);
valuesCodeMirror.on("change", onChange);
onChange();
})
.catch((error) => {
console.error(error);
});
});
</script>
<script
src="https://cdn.usefathom.com/script.js"
data-site="ZNCHLJMX"
defer
></script>
</body>
</html>