Skip to content

Commit fd3c93d

Browse files
committed
Modified templatize to ignore non-haml files
1 parent fe3ba8b commit fd3c93d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

hamlpy/templatize.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
"""
22
This module decorates the django templatize function to parse haml templates
33
before the translation utility extracts tags from it.
4+
5+
--Modified to ignore non-haml files.
46
"""
5-
7+
68
try:
79
from django.utils.translation import trans_real
810
_django_available = True
911
except ImportError, e:
1012
_django_available = False
11-
13+
1214
import hamlpy
13-
14-
15+
import os
16+
17+
1518
def decorate_templatize(func):
16-
def templatize(src, origin=None):
17-
hamlParser = hamlpy.Compiler()
18-
html = hamlParser.process(src.decode('utf-8'))
19-
return func(html.encode('utf-8'), origin)
20-
21-
return templatize
22-
19+
def templatize(src, origin=None):
20+
#if the template has no origin file then do not attempt to parse it with haml
21+
if origin:
22+
#if the template has a source file, then only parse it if it is haml
23+
if os.path.splitext(origin)[1].lower() in ['.'+x.lower() for x in hamlpy.VALID_EXTENSIONS]:
24+
hamlParser = hamlpy.Compiler()
25+
html = hamlParser.process(src.decode('utf-8'))
26+
src = html.encode('utf-8')
27+
return func(src, origin)
28+
return templatize
29+
2330
if _django_available:
24-
trans_real.templatize = decorate_templatize(trans_real.templatize)
25-
31+
trans_real.templatize = decorate_templatize(trans_real.templatize)

0 commit comments

Comments
 (0)