-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For this release, a substantial part the codebase has been refactored. Here is a non-exhaustive summary of all the things that have changed: - Support for Python 3.6 and 3.7 has been dropped - A Django middleware class to indent HTML responses has been added - Ignore both opening and closing comment tags - New handling off both relative and absolute offsets - Return correct `repr()` strings with the `--debug` option - New token class "OpenDouble" and a revised indentation algorithm - Additional `line` argument to `create_token()` methods - Changed return value of `create_token()` methods - Changed constructor arguments of Token and Line classes - Refactored all `create_token()` methods to get rid of return statements - Simplified test suite runner that reindents the expected output - Don't indent the contents of template variables (closes #75) - Improved handling of Django tags inside HTML elements - Improved JavaScript `case` indentation (closes #76) - Improved JavaScript method chaining (closes #59) - Improved CSS multiline statements (closes #74) - New multiline HTML element indentation (closes #50) - New multiline HTML attribute value indentation - Extensive test coverage with lots of edge cases
- Loading branch information
Showing
28 changed files
with
805 additions
and
1,261 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from djhtml.modes import DjHTML | ||
|
||
try: | ||
TABWIDTH = settings.TABWIDTH | ||
except AttributeError: | ||
TABWIDTH = 4 | ||
|
||
|
||
class DjHTMLMiddleware: | ||
""" | ||
Django middleware class to indent HTML responses. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
if ( | ||
"Content-Type" in response | ||
and response["Content-Type"] == "text/html; charset=utf-8" | ||
): | ||
if "Content-Length" in response: | ||
raise ImproperlyConfigured( | ||
"Please load DjHTMLMiddleware _after_ CommonMiddleware (otherwise" | ||
' the "Content-Length" header will be incorrect)' | ||
) | ||
response.content = ( | ||
DjHTML(response.content.decode()).indent(TABWIDTH).encode() | ||
) | ||
return response |
Oops, something went wrong.