From 3b5f0770be1f9d7547f3ee423c26702d06fb8d82 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Tue, 7 Dec 2021 21:08:18 +0400 Subject: [PATCH 1/4] Fix fail_safe option not working --- flask_minify/parsers.py | 7 +++---- tests/integration.py | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/flask_minify/parsers.py b/flask_minify/parsers.py index cce6050..6ec78cd 100644 --- a/flask_minify/parsers.py +++ b/flask_minify/parsers.py @@ -109,11 +109,10 @@ def minify(self, content, tag): } try: - minified = parser.executer(content, **runtime_options) + minified_or_content = parser.executer(content, **runtime_options) except Exception as e: - minified = parser.executer(content, **runtime_options) if not self.fail_safe: raise e - minified = content + minified_or_content = content - return minified + return minified_or_content diff --git a/tests/integration.py b/tests/integration.py index 304d178..095fcb7 100644 --- a/tests/integration.py +++ b/tests/integration.py @@ -102,8 +102,6 @@ def test_minify_cache(client): def test_fail_safe(client): """testing fail safe enabled with false input""" store_minify.parser.fail_safe = True - store_minify.cssless = False - store_minify.parser.runtime_options["html"]["minify_inline"] = {} resp = client.get("/cssless_false") assert bytes(FALSE_LESS.encode("utf-8")) == resp.data From e83643ac60edaf0e08d24b2b7734bf87feb5735e Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Tue, 7 Dec 2021 21:13:23 +0400 Subject: [PATCH 2/4] Cleanup module imports --- flask_minify/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_minify/__init__.py b/flask_minify/__init__.py index 89b77f9..1f26e71 100644 --- a/flask_minify/__init__.py +++ b/flask_minify/__init__.py @@ -1,3 +1,3 @@ -from . import decorators from .about import __author__, __doc__, __email__, __license__, __version__ +from .main import Minify from .main import Minify as minify From 01fa443129b5f01488e72cf5886b725ae734b652 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Tue, 7 Dec 2021 21:13:37 +0400 Subject: [PATCH 3/4] Fix and cleanup readme examples --- README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f4dccc8..965da88 100644 --- a/README.md +++ b/README.md @@ -37,23 +37,23 @@ In this example the extension will minify every HTML request, unless it's expli ```python from flask import Flask -from flask_minify import minify +from flask_minify import Minify app = Flask(__name__) -minify(app=app, html=True, js=True, cssless=True) +Minify(app=app, html=True, js=True, cssless=True) ``` Another approach is using **decorators**, you can set the extension to be `passive` so will only minify the decorated routes ```python from flask import Flask -from flask_minify import minify, decorators +from flask_minify import Minify, decorators as minify_decorators app = Flask(__name__) -minify(app=app, passive=True) +Minify(app=app, passive=True) @app.route('/') -@decorators.minify(html=True, js=True, cssless=True) +@minify_decorators.minify(html=True, js=True, cssless=True) def example(): return '

Example...

' ``` @@ -92,7 +92,7 @@ both options can handle regex patterns as input so for example, if you want to b you can just pass the pattern as such: ```python -minify(app, bypass=['blueprint_name.*']) +Minify(app, bypass=['blueprint_name.*']) ``` #### - `caching_limit` @@ -111,19 +111,17 @@ allows passing tag specific options to the module responsible for the minificati In the following example will replace the default `style` (handles CSS) parser `rcssmin` with `lesscpy`: ```python -from flask_minify import minify -from flask_minify.parsers import as minify_parsers +from flask_minify import Minify, parsers as minify_parsers parsers = {'style': minify_parsers.Lesscpy} -minify(app=app, parsers=parsers) +Minify(app=app, parsers=parsers) ``` you can override the default parser runtime options as well, as shown in the following example: ```python -from flask_minify import minify -from flask_minify.parsers import as minify_parsers +from flask_minify import Minify, parsers as minify_parsers class CustomCssParser(minify_parsers.Lesscpy): runtime_options = { @@ -133,7 +131,7 @@ class CustomCssParser(minify_parsers.Lesscpy): parsers = {'style': CustomCssParser} -minify(app=app, parsers=parsers) +Minify(app=app, parsers=parsers) ``` the **default** parsers are set to `{"html": Html, "script": Jsmin, "style": Rcssmin}` check out [the code](https://github.com/mrf345/flask_minify/blob/master/flask_minify/parsers.py) for more insight. @@ -150,4 +148,4 @@ the **default** parsers are set to `{"html": Html, "script": Jsmin, "style": Rcs #### `0.33` introduces a breaking change to the expected output, in this release `lesscpy` will be replaced by `cssmin` as -the default css minifier so no more `less` compiling by default. in case you don't want that, follow [this example](https://github.com/mrf345/flask_minify#--parsers). \ No newline at end of file +the default css minifier so no more `less` compiling by default. in case you don't want that, follow [this example](https://github.com/mrf345/flask_minify#--parsers). From c0629efaa57e09cf80e51e0baa6b7392a360bf92 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Tue, 7 Dec 2021 21:13:47 +0400 Subject: [PATCH 4/4] Bump version to 0.35 --- flask_minify/about.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_minify/about.py b/flask_minify/about.py index 11d0cb0..a84ec1d 100644 --- a/flask_minify/about.py +++ b/flask_minify/about.py @@ -1,4 +1,4 @@ -__version__ = "0.34" +__version__ = "0.35" __doc__ = "Flask extension to minify html, css, js and less." __license__ = "MIT" __author__ = "Mohamed Feddad"