def visitNode_body(self, node): tocs=domhelpers.locateNodes([node], 'class', 'toc') domhelpers.clearNode(node) if len(tocs): toc=tocs[0] node.appendChild(toc) self.visitNodeDefault(node)
def visitNode_body(self, node): tocs = domhelpers.locateNodes([node], 'class', 'toc') domhelpers.clearNode(node) if len(tocs): toc = tocs[0] node.appendChild(toc) self.visitNodeDefault(node)
def test_clearNode(self): doc1 = self.dom.parseString('<a><b><c><d/></c></b></a>') a_node = doc1.documentElement domhelpers.clearNode(a_node) self.assertEqual(a_node.toxml(), self.dom.Element('a').toxml()) doc2 = self.dom.parseString('<a><b><c><d/></c></b></a>') b_node = doc2.documentElement.childNodes[0] domhelpers.clearNode(b_node) actual = doc2.documentElement.toxml() expected = self.dom.Element('a') expected.appendChild(self.dom.Element('b')) self.assertEqual(actual, expected.toxml())
def setUp(self, request, node, data): if isinstance(data, StringType): node.tagName = self.tagName node.attributes["href"] = data else: data = self.model txt = data.getSubmodel(request, "text").getData(request) if not isinstance(txt, Node): txt = document.createTextNode(txt) lnk = data.getSubmodel(request, "href").getData(request) self['href'] = lnk node.tagName = self.tagName domhelpers.clearNode(node) node.appendChild(txt)
def setUp(self, request, node, data): # TODO: we ought to support Deferreds here for both text and href! if isinstance(data, StringType): node.tagName = self.tagName node.attributes["href"] = data else: data = self.model txt = data.getSubmodel(request, "text").getData(request) if not isinstance(txt, Node): txt = document.createTextNode(txt) lnk = data.getSubmodel(request, "href").getData(request) self['href'] = lnk node.tagName = self.tagName domhelpers.clearNode(node) node.appendChild(txt)
def test_clearNode(self): doc1 = self.dom.parseString('<a><b><c><d/></c></b></a>') a_node = doc1.documentElement domhelpers.clearNode(a_node) self.assertEqual( a_node.toxml(), self.dom.Element('a').toxml()) doc2 = self.dom.parseString('<a><b><c><d/></c></b></a>') b_node = doc2.documentElement.childNodes[0] domhelpers.clearNode(b_node) actual = doc2.documentElement.toxml() expected = self.dom.Element('a') expected.appendChild(self.dom.Element('b')) self.assertEqual(actual, expected.toxml())
def setUp(self, request, node, data): # TODO: we ought to support Deferreds here for both text and href! if isinstance(data, StringType): node.tagName = 'a' node.setAttribute("href", data) else: data = self.model txt = data.getSubmodel("text").getData(request) if not isinstance(txt, Node): txt = document.createTextNode(txt) lnk = data.getSubmodel("href").getData(request) self['href'] = lnk node.tagName = 'a' domhelpers.clearNode(node) node.appendChild(txt)
def generateDOM(self, request, node): node = Widget.generateDOM(self, request, node) listHeader = self.getPattern('listHeader', None) listFooter = self.getPattern('listFooter', None) emptyList = self.getPattern('emptyList', None) domhelpers.clearNode(node) if not listHeader is None: node.appendChild(listHeader) data = self.getData(request) if data: self._iterateData(node, self.submodel, data) elif not emptyList is None: node.appendChild(emptyList) if not listFooter is None: node.appendChild(listFooter) return node
def generateDOM(self, request, node): node = Widget.generateDOM(self, request, node) listHeaders = self.getAllPatterns('listHeader', None) listFooters = self.getAllPatterns('listFooter', None) emptyLists = self.getAllPatterns('emptyList', None) domhelpers.clearNode(node) if listHeaders: node.childNodes.extend(listHeaders) for n in listHeaders: n.parentNode = node data = self.getData(request) if data: self._iterateData(node, self.submodel, data) elif emptyLists: node.childNodes.extend(emptyLists) for n in emptyLists: n.parentNode = node if listFooters: node.childNodes.extend(listFooters) for n in listFooters: n.parentNode = node return node
def setUp(self, request, node, data): pattern = self.getPattern('columnListRow', clone=0) if self.end: listSize = self.end - self.start if listSize > len(data): listSize = len(data) else: listSize = len(data) for itemNum in range(listSize): if itemNum % self.columns == 0: row = self.getPattern('columnListRow') domhelpers.clearNode(row) node.appendChild(row) newNode = self.getPattern('columnListItem') appendModel(newNode, itemNum + self.start) if not newNode.attributes.get("view"): newNode.attributes["view"] = "DefaultWidget" row.appendChild(newNode) node.removeChild(pattern) return node
def test_clearNode(self): doc1=microdom.parseString('<a><b><c><d/></c></b></a>') a_node=doc1.documentElement domhelpers.clearNode(a_node) actual=doc1.documentElement.toxml() expected='<a></a>' assert actual==expected, 'expected %s, got %s' % (expected, actual) doc2=microdom.parseString('<a><b><c><d/></c></b></a>') b_node=doc2.documentElement.childNodes[0] domhelpers.clearNode(b_node) actual=doc2.documentElement.toxml() expected='<a><b></b></a>' assert actual==expected, 'expected %s, got %s' % (expected, actual) doc3=microdom.parseString('<a><b><c><d/></c></b></a>') c_node=doc3.documentElement.childNodes[0].childNodes[0] domhelpers.clearNode(c_node) actual=doc3.documentElement.toxml() expected='<a><b><c></c></b></a>' assert actual==expected, 'expected %s, got %s' % (expected, actual)
def test_clearNode(self): doc1 = microdom.parseString('<a><b><c><d/></c></b></a>') a_node = doc1.documentElement domhelpers.clearNode(a_node) actual = doc1.documentElement.toxml() expected = '<a></a>' assert actual == expected, 'expected %s, got %s' % (expected, actual) doc2 = microdom.parseString('<a><b><c><d/></c></b></a>') b_node = doc2.documentElement.childNodes[0] domhelpers.clearNode(b_node) actual = doc2.documentElement.toxml() expected = '<a><b></b></a>' assert actual == expected, 'expected %s, got %s' % (expected, actual) doc3 = microdom.parseString('<a><b><c><d/></c></b></a>') c_node = doc3.documentElement.childNodes[0].childNodes[0] domhelpers.clearNode(c_node) actual = doc3.documentElement.toxml() expected = '<a><b><c></c></b></a>' assert actual == expected, 'expected %s, got %s' % (expected, actual)