Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace go html parser deprecated option #96

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_minify/about.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.46"
__version__ = "0.47"
__doc__ = "Flask extension to minify html, css, js and less."
__license__ = "MIT"
__author__ = "Mohamed Feddad"
Expand Down
8 changes: 6 additions & 2 deletions flask_minify/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def executer(self, content, **options):
class HtmlGo(GoParserMixin):
runtime_options = _o = {
"html-keep-comments": False,
"html-keep-conditional-comments": True,
"html-keep-special-comments": True,
"html-keep-default-attr-vals": True,
"html-keep-document-tags": True,
"html-keep-end-tags": True,
Expand Down Expand Up @@ -131,12 +131,16 @@ def __init__(
self.fail_safe = fail_safe
self.go = go

if any(p.go for p in self.parsers.values()) and not minify_go:
if self.has_go_parser and not minify_go:
raise FlaskMinifyException(
f"Cannot use any Go parsers without installing "
"Go optional dependency: `pip install flask-minify[go]`"
)

@property
def has_go_parser(self):
return any(p.go for p in self.parsers.values())

def update_runtime_options(
self, html=False, js=False, cssless=False, script_types=[]
):
Expand Down
2 changes: 1 addition & 1 deletion requirements/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ htmlminf
jsmin
xxhash
rcssmin
tdewolff-minify[go]; platform_system == "Linux"
tdewolff-minify[go]>=2.20.34; platform_system == "Linux"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup

supported_versions = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
optional_requirements = {"go": 'tdewolff-minify; platform_system == "Linux"'}
optional_requirements = {"go": 'tdewolff-minify>=2.20.34; platform_system == "Linux"'}
basedir = path.abspath(path.dirname(__file__))
long_description = ""
requirements = []
Expand Down
14 changes: 14 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@
]
)

HTML_CONDITIONAL_COMMENTS = """
<html>
<header>
<!--[if IE]>
IE comment!
<![endif]-->
</header>
</html>
"""

MINIFIED_HTML_CONDITIONAL_COMMENTS = (
b"<html><header><!--[if IE]>IE comment!<![endif]--></header></html>"
)

MINIFIED_HTML = b"<html><body><h1> HTML </h1></body></html>"
MINIFIED_HTML_GO = b"<html><body><h1>HTML</h1></body></html>"

Expand Down
8 changes: 8 additions & 0 deletions tests/integration_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
LESS,
LESS_RAW,
MINIFIED_CSS_EDGE_CASES_GO,
MINIFIED_HTML_CONDITIONAL_COMMENTS,
MINIFIED_HTML_EMBEDDED_TAGS_GO,
MINIFIED_HTML_GO,
MINIFIED_JS,
Expand Down Expand Up @@ -265,3 +266,10 @@ def test_unicode_endpoint(client):

assert resp.status == "200 OK"
assert resp.data.decode("utf-8") == "–"


@pytest.mark.skipif(is_windows, reason=skip_reason)
def test_go_html_minify_conditional_comments(client):
"""testing go HTML minify with conditional comments"""
resp = client.get("/conditional-comments")
assert MINIFIED_HTML_CONDITIONAL_COMMENTS == resp.data
5 changes: 5 additions & 0 deletions tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
FALSE_JS,
FALSE_LESS,
HTML,
HTML_CONDITIONAL_COMMENTS,
HTML_EMBEDDED_TAGS,
JS,
JS_WITH_TYPE,
Expand Down Expand Up @@ -94,4 +95,8 @@ def html_embedded():
def unicode_endpoint():
return "–"

@app.route("/conditional-comments")
def conditional_comments():
return HTML_CONDITIONAL_COMMENTS

return app, store_minify
Loading