Rick Copeland avatar Rick Copeland committed 6f4a728

Add xml blocks

Comments (0)

Files changed (3)

-* XML blocks
 * XML closures
 * XML PIs
 * XML Comment tests

fastpt/tests/v2/test_xml.py

         py:block="block"
         py:extends="extends">Foo</div>''').parse()
         fpt.xml_template.expand(doc)
-        print doc.toprettyxml()
         node = doc.childNodes[0]
         for tagname, attr in fpt.markup_template.QDIRECTIVES:
+            if node.tagName == 'div':
+                node = node.childNodes[0]
+                continue
             assert node.tagName == tagname, '%s != %s' %(
                 node.tagName, tagname)
             if attr:
 Thanks for the gift!</p>
 
 ${sign(from_)}
-</div>
-'''),
+</div>'''),
                 'child.html':XMLTemplate('''<py:extends href="parent.html"
 ><py:def function="greet(name)"
 >Dear $name:</py:def
-><p py:block="body">${parent_block()}
-And don't forget you owe me money!
-</p>
-</py:extends>
+><py:block name="body">${parent_block()}
+<p>And don't forget you owe me money!</p>
+</py:block
+></py:extends>
 ''')})
         parent = loader.import_('parent.html')
         rsp = parent({'to':'Mark', 'from_':'Rick'}).__fpt__.render()
-        print rsp
-        child = loader.import_('child.txt')
+        assert rsp == '''<div>Hello, Mark!
+
+<p>It was good seeing you last Friday.
+Thanks for the gift!</p>
+
+Sincerely,<br/><em>Rick</em>
+</div>''', rsp
+        child = loader.import_('child.html')
         rsp = child({'to':'Mark', 'from_':'Rick'}).__fpt__.render()
-        print rsp
-        return
-        assert (rsp=='''Dear Mark:
-It was good seeing you last Friday.  Thanks for the gift!
+        assert rsp=='''<div>Dear Mark:
 
-And don't forget you owe me money!
+<p>It was good seeing you last Friday.
+Thanks for the gift!</p>
+<p>And don't forget you owe me money!</p>
 
-Sincerely,
-Rick
-'''), rsp
-        
+
+Sincerely,<br/><em>Rick</em>
+</div>''', rsp
 
 if __name__ == '__main__':
     main()

fastpt/v2/xml_template.py

         href = node.getAttribute('href')
         yield ir.IncludeNode(href)
 
+    def _compile_block(self, node):
+        fname = '_fpt_block_' + node.getAttribute('name')
+        decl = fname + '()'
+        body = list(self._compile_nop(node))
+        self.functions[decl] = body
+        if self.is_child:
+            parent_block = 'parent.' + fname
+            body.insert(0, ir.PythonNode(ir.TextNode('parent_block=%s' % parent_block)))
+        else:
+            yield ir.ExprNode(decl)
+
     def _compile_def(self, node):
         old_in_def, self.in_def = self.in_def, True
         body = self._compile_nop(node)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.