Commits

Juan BC  committed 258142a

fixed correct closed tag TODO: incorrect closed

  • Participants
  • Parent commits da9a4c1

Comments (0)

Files changed (2)

File test/coso.html

             import random
             import datetime
             echo(random.randint(0, 99))
-            echo("<hola></hola>")
+            echo("<python>")
             #APP.algo = 1
         </python>
 

File trex/renderer.py

 # CONSTANTS
 #===============================================================================
 
-# TAG for embebed python into html <python> ... </python>
+# TAG for embebed python into html.
 PYTHON_HTML_TAG = "python"
 
 OUTPUT_TAG = "span"
 
-XPATH = "//python" #[ancestor::name!='python']"
+_XPATH = "//%s[not(ancestor::%s)]" % (PYTHON_HTML_TAG, PYTHON_HTML_TAG)
+
 
 #===============================================================================
 # ERROR
         child_elements = {}
         template_globals = globals()
         template_locals = {}
-        for py_element in dom.iterfind(XPATH):
+        for py_element in dom.xpath(_XPATH):
             
             #preserve the attributes and tail for the output
             attribs = dict(py_element.attrib)
             # format code
             src, cs = self._stringify(py_element)
             src = self._format_code(src)
+            
+            # execute code
             response_list = []
-            
             template_locals.update(echo=response_list.append)
             if src:
+                print src
                 exec(src, template_globals, template_locals)
             response = "".join([str(e) for e in response_list])
             
         
         render = etree.tostring(dom.getroot(), encoding="utf-8",
                                 pretty_print=True, method="html")
+        
+        # restore the child elements
         for k, v in child_elements.items():
             render = render.replace(k, v, 1)
         return render
     def paths(self):
         return self._paths
 
-print Renderer().render("/home/juan/proyectos/trex_hg/test/coso.html")
 
 #===============================================================================
 # MAIN