UNPKG

pragma-views2

Version:

1 lines 1.03 kB
import{domCaseMap}from"./binding/document-casemap.js";export function inflateTemplate(e,t){const n=Array.from(e.children);for(let e of n)e.children.length>0?inflateTemplate(e,t):null!=e.innerText&&inflateInnerText(e,t),inflateAttributes(e,t);return e}export function inflateAttributes(e,t){const n=Array.from(e.attributes);for(let e of n)inflateAttribute(e,t)}export function inflateAttribute(e,t){if(-1!=e.nodeValue.indexOf("#")){const n=getModelValue(t,e.nodeValue),r=domCaseMap.has(e.name)?domCaseMap.get(e.name):e.name;"innerHTML"==r?e.ownerElement.innerHTML=n:e.ownerElement.setAttribute(r,n)}}export function inflateInnerText(e,t){e.innerText.indexOf("#")>-1&&(e.innerText=getModelValue(t,e.innerText))}export function setAttribute(e,t){const n=Object.keys(t);for(let r of n)e.setAttribute(r,t[r])}function getModelValue(e,t){return getValue(e,t.split("#").join(""))}function getValue(e,t){if(-1==t.indexOf("."))return e[t];const n=t.split(".");if(2==n.length)return e[n[1]];return getValue(e[n[1]],n.slice(1).join("."))}