Improve HTML render helper
This commit is contained in:
parent
cf4455ca7a
commit
f740bf3957
1 changed files with 11 additions and 2 deletions
13
render.js
13
render.js
|
@ -1,3 +1,12 @@
|
||||||
|
const parseAttribute = (attribute) => {
|
||||||
|
if (typeof(attribute) == "string")
|
||||||
|
return attribute
|
||||||
|
else if ("join" in attribute)
|
||||||
|
return attribute.join(" ")
|
||||||
|
else
|
||||||
|
return JSON.stringify(attribute)
|
||||||
|
}
|
||||||
|
|
||||||
const parseArgs = (element, args) => {
|
const parseArgs = (element, args) => {
|
||||||
for (arg of args)
|
for (arg of args)
|
||||||
if (typeof(arg) == "string")
|
if (typeof(arg) == "string")
|
||||||
|
@ -8,11 +17,11 @@ const parseArgs = (element, args) => {
|
||||||
parseArgs(element, arg)
|
parseArgs(element, arg)
|
||||||
else
|
else
|
||||||
for (key in arg)
|
for (key in arg)
|
||||||
element.setAttribute(key, arg[key])
|
element.setAttribute(key.replace("_", "-"), parseAttribute(arg[key]))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const node = (name, args) => {
|
export const node = (name, args) => {
|
||||||
const element = document.createElement(name)
|
const element = document.createElement(name.replace("_", "-"))
|
||||||
parseArgs(element, args)
|
parseArgs(element, args)
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue