Skip to content
Browse files

Merge pull request #144 from cordery/master

Fix to templatize decorator so it only hamlpy parses files with valid haml extensions see Issue #96
  • Loading branch information...
2 parents ab51afb + 62bc8cb commit acb79e14381ce46e6d1cb64e7cb154751ae02dfe @jessemiller committed Aug 27, 2013
Showing with 13 additions and 7 deletions.
  1. +13 −7 hamlpy/templatize.py
View
20 hamlpy/templatize.py
@@ -1,6 +1,8 @@
"""
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:
@@ -10,16 +12,20 @@
_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)
-

0 comments on commit acb79e1

Please sign in to comment.
Something went wrong with that request. Please try again.