2021-06-23 14:21:33 +00:00
|
|
|
/*
|
|
|
|
A simple function to more easily write HTML in Javascript
|
|
|
|
|
|
|
|
Example:
|
|
|
|
const greeting = name => template`<p>Hello, ${name}!</p><br>`
|
|
|
|
document.append(greeting(bob).cloneNode(true))
|
|
|
|
*/
|
|
|
|
|
2021-02-17 10:02:58 +00:00
|
|
|
export const template = (strings, ...args) => {
|
2020-10-27 15:29:29 +00:00
|
|
|
let buf = []
|
2021-05-20 11:15:05 +00:00
|
|
|
for (let i=0;i<strings.length;i++) {
|
2020-10-27 15:29:29 +00:00
|
|
|
buf.push(strings[i], args[i])
|
|
|
|
}
|
|
|
|
let template = document.createElement("template")
|
|
|
|
template.innerHTML = buf.join("")
|
2021-02-22 19:24:17 +00:00
|
|
|
return template.content
|
2020-10-27 15:29:29 +00:00
|
|
|
}
|