def _expandTemplatesDW(self): tbe = 'TemplateBeginEditable name="%s"' tee = 'TemplateEndEditable' dwtemplates = [d.cloneNode(1) for d in self._templates] for i in dwtemplates: for master in self._templates: if getclass(i) == getname(master): child = master.cloneNode(1) attset(child, nm, getname(i)) attdel(child, cls) self._expandFragmentsDW(child, i) dwtemplates.remove(i) dwtemplates.append(child) i = child fields = [f for f in tags(i, psins, fld)] for field in fields: pn = field.parentNode ppn = pn.parentNode.insertBefore ttbe = self._doc.createComment(tbe % getname(field)) ttee = self._doc.createComment(tee) ppn(ttbe, pn) ppn(ttee, pn.nextSibling) ph = self._doc.createTextNode(getname(i)) field.parentNode.replaceChild(ph, field) self._exports['/Templates/%s.dwt' % getname(i)] = i.firstChild self._expand(self._templates, self._expandFragments, self._cleanTemplates) self._cleanUnexpanded()
def _expand(self, lo, fragment, end): for resource in lo: for master in self._templates: if getclass(resource) == getname(master): child = master.cloneNode(1) attset(child, nm, getname(resource)) attdel(child, cls) fragment(child, resource) resource.parentNode.appendChild(child) resource.parentNode.removeChild(resource) end(child, resource)
def tostatic(self, file=None): self._exports = {} if file: self._doc = nr.parseUri(file) stripws(self._doc) names = [getname(i) for i in tags(self._doc, psins, rsrc)] classes = [getclass(i) for i in tags(self._doc, psins, rsrc)] self._unexpanded = [i for i in tags(self._doc, psins, rsrc) if getclass(i) in names] self._templates = [i for i in tags(self._doc, psins, rsrc) if getname(i) in classes] self._expandTemplates() self._expandResources() self._exportResources()
def _expandFragmentsDW(self, source, target): tbe = 'InstanceBeginEditable name="%s"' tee = 'InstanceEndEditable' fields = [f for f in tags(source, psins, fld)] fragments = [f for f in tags(target, psins, fmnt)] for fragment in fragments: fclass = getclass(fragment) for field in fields: if fclass == getname(field): pn = field.parentNode ppn = pn.parentNode.insertBefore ttbe = self._doc.createComment(tbe % getname(field)) ttee = self._doc.createComment(tee) ppn(ttbe, field.parentNode) for child in fragment.childNodes: clone = child.cloneNode(1) pn.insertBefore(clone, field) ppn(ttee, pn.nextSibling) for field in fields: field.parentNode.removeChild(field)
def _exportPackDW(self, child, resource): tbe = '''InstanceBegin template="/Templates/%s.dwt" codeOutsideHTMLIsLocked="false"''' tee = 'InstanceEnd' instance = child.firstChild ttbe = self._doc.createComment(tbe % getclass(resource)) ttee = self._doc.createComment(tee) instance.insertBefore(ttbe, instance.firstChild) instance.appendChild(ttee) self._exports[getname(resource)] = instance
def _expandFragments(self, source, target): fields = [f for f in tags(source, psins, fld)] fragments = [f for f in tags(target, psins, fmnt)] for fragment in fragments: fclass = getclass(fragment) for field in fields: if fclass == getname(field): for child in fragment.childNodes: clone = child.cloneNode(1) field.parentNode.insertBefore(clone, field) for field in fields: field.parentNode.removeChild(field)
def _exportPack(self, child, resource): self._exports[getname(resource)] = child.firstChild
def _cleanUnexpanded(self): for resource in self._unexpanded: name = getname(resource) for template in self._templates: if name == getname(template): self._unexpanded.remove(resource)