File tree 1 file changed +19
-13
lines changed
1 file changed +19
-13
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
This module decorates the django templatize function to parse haml templates
3
3
before the translation utility extracts tags from it.
4
+
5
+ --Modified to ignore non-haml files.
4
6
"""
5
-
7
+
6
8
try :
7
9
from django .utils .translation import trans_real
8
10
_django_available = True
9
11
except ImportError , e :
10
12
_django_available = False
11
-
13
+
12
14
import hamlpy
13
-
14
-
15
+ import os
16
+
17
+
15
18
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
+
23
30
if _django_available :
24
- trans_real .templatize = decorate_templatize (trans_real .templatize )
25
-
31
+ trans_real .templatize = decorate_templatize (trans_real .templatize )
You can’t perform that action at this time.
0 commit comments