-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
47 lines (36 loc) · 1012 Bytes
/
example.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
<!DOCTYPE html>
<html>
<head>
<!-- imports recommended -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="/spay.js"></script>
</head>
<body>
<!-- html to append in -->
<div id="example"></div>
<!-- template to use -->
<!-- uses string templating syntax -->
<!-- avoid/escape backticks (`) -->
<template id="template">
<h2>${header}</h2>
<p>${body}</p>
</template>
<!-- usage -->
<script>
// spay.get( url, destination, template )
// IMPORTANT: JSON ENDPOINT SHOULD HAVE SANITIZED OUTPUT
spay.get("/example.json", "#example", "#template");
/* example.json
{
"header": "Hello dev",
"body": "Welcome to SPA-Y"
}
*/
/* outputs
<h2>Hello dev</h2>
<p>Welcome to SPA-Y</p>
*/
</script>
</body>
</html>