From fd3c93d71e3688c3fdf556cd770ff0f522226872 Mon Sep 17 00:00:00 2001 From: Andrew Cordery Date: Thu, 22 Aug 2013 23:25:30 -0400 Subject: [PATCH] Modified templatize to ignore non-haml files --- hamlpy/templatize.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hamlpy/templatize.py b/hamlpy/templatize.py index 998d4f2..8497284 100644 --- a/hamlpy/templatize.py +++ b/hamlpy/templatize.py @@ -1,25 +1,31 @@ """ This module decorates the django templatize function to parse haml templates before the translation utility extracts tags from it. + +--Modified to ignore non-haml files. """ - + try: from django.utils.translation import trans_real _django_available = True except ImportError, e: _django_available = False - + import hamlpy - - +import os + + def decorate_templatize(func): - def templatize(src, origin=None): - hamlParser = hamlpy.Compiler() - html = hamlParser.process(src.decode('utf-8')) - return func(html.encode('utf-8'), origin) - - return templatize - + def templatize(src, origin=None): + #if the template has no origin file then do not attempt to parse it with haml + if origin: + #if the template has a source file, then only parse it if it is haml + if os.path.splitext(origin)[1].lower() in ['.'+x.lower() for x in hamlpy.VALID_EXTENSIONS]: + hamlParser = hamlpy.Compiler() + html = hamlParser.process(src.decode('utf-8')) + src = html.encode('utf-8') + return func(src, origin) + return templatize + if _django_available: - trans_real.templatize = decorate_templatize(trans_real.templatize) - + trans_real.templatize = decorate_templatize(trans_real.templatize) \ No newline at end of file