-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified templatize to ignore non-haml files
- Loading branch information
Showing
1 changed file
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
fd3c93d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
html = hamlParser.process(src.decode('utf-8'))
this might throw aUnicodeEncodeError
when usingmakemessages
.