Commits

Rick Copeland committed 412d1d1

Verify line number tracking in text templates

  • Participants
  • Parent commits 04885c3

Comments (0)

Files changed (6)

-* Track line number information in Text  templates
-* Update lnotab and source filename on template functions to reflect template info
-* Write CSS => IR compiler (and document language)
-   - Make sure it replicates the features of Sass plus even more
 * Template designer documentation for text templates
 * Template designer documentation for xml templates
-* Template designer documentation for CSS templates

File kajiki/__init__.py

 from .loader import MockLoader, FileLoader
 from .text import TextTemplate
 from .xml_template import XMLTemplate
+from .css import CSSTemplate

File kajiki/tests/data/debug.txt

+%def one()
+${two()}
+%end
+%def two()
+${three()}
+%end
+%def three()
+%py raise ValueError, 'Test error'
+%end
+${one()}

File kajiki/tests/test_text.py

+import os
+import sys
+import traceback
 from unittest import TestCase, main
 
-from kajiki import MockLoader, TextTemplate
+from kajiki import MockLoader, FileLoader, TextTemplate
 
 class TestBasic(TestCase):
 
         rsp = tpl(dict(name='Rick')).__kj__.render()
         assert rsp == 'a/b/c'
 
+class TestDebug(TestCase):
+    
+    def test_debug(self):
+        loader = FileLoader(base=os.path.join(os.path.dirname(__file__), 'data'))
+        tpl = loader.import_('debug.txt')
+        try:
+            tpl().__kj__.render()
+            assert False, 'Should have raised ValueError'
+        except ValueError:
+            exc_info = sys.exc_info()
+            stack = traceback.extract_tb(exc_info[2])
+        # Verify we have stack trace entries in the template
+        for fn, lno, func, line in stack:
+            if fn.endswith('debug.txt'): break
+        else:
+            assert False, 'Stacktrace is all python'
+
 if __name__ == '__main__':
     main()

File kajiki/text.py

         filename = '<string>'
     scanner = _Scanner(filename, source)
     tree = _Parser(scanner).parse()
+    tree.filename = filename
     return kajiki.template.from_ir(tree)
 
 class _Scanner(object):
       you still long for the assurance that your output is well-formed that you
       miss from all those other templating engines? Do you wish you had Jinja's
       blocks with Genshi's syntax? Then look  no further, Kajiki is for you!
-      Kajiki uses the stdlib's HTMLParser to *quickly* compile Genshi-like syntax to *real python
-      bytecode* that renders with blazing-fast speed! Don't delay! Pick up your
+      Kajiki quickly compiles Genshi-like syntax to *real python bytecode*
+      that renders with blazing-fast speed! Don't delay! Pick up your
       copy of Kajiki today!""",  
       classifiers=[
         'Development Status :: 3 - Alpha',