From 8f1056a3677e530978ce66aa695ab9b196f128bd Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 25 Nov 2018 13:20:06 -0800 Subject: [PATCH] Support .sass extension for the wsgi middleware --- sasstests.py | 26 ++++++++++++++++++++++++++ sassutils/builder.py | 10 ++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/sasstests.py b/sasstests.py index 8fd204d4..70ff9eac 100644 --- a/sasstests.py +++ b/sasstests.py @@ -752,6 +752,32 @@ def test_wsgi_sass_middleware_without_extension(self): self.assertEqual(expected.encode(), r.data) assert r.mimetype == 'text/css' + def test_wsgi_sass_middleware_without_extension_sass(self): + with tempdir() as css_dir: + src_dir = os.path.join(css_dir, 'src') + os.makedirs(src_dir) + with open(os.path.join(src_dir, 'a.sass'), 'w') as f: + f.write('a\n\tb\n\t\tcolor: blue;') + app = SassMiddleware( + self.sample_wsgi_app, { + __name__: { + 'sass_path': src_dir, + 'css_path': css_dir, + 'wsgi_path': '/static', + 'strip_extension': True, + }, + }, + ) + client = Client(app, Response) + r = client.get('/static/a.css') + assert r.status_code == 200 + expected = ( + 'a b {\n color: blue; }\n\n' + '/*# sourceMappingURL=../a.css.map */' + ) + self.assertEqual(expected.encode(), r.data) + assert r.mimetype == 'text/css' + class DistutilsTestCase(BaseTestCase): diff --git a/sassutils/builder.py b/sassutils/builder.py index 29e48786..4af08928 100644 --- a/sassutils/builder.py +++ b/sassutils/builder.py @@ -199,8 +199,14 @@ def unresolve_filename(self, filename): """ filename, _ = os.path.splitext(filename) if self.strip_extension: - filename = filename + '.scss' - return filename + for ext in ('.scss', '.sass'): + test_path = os.path.join(self.sass_path, filename + ext) + if os.path.exists(test_path): + return filename + ext + else: # file not found, let it error with `.scss` extension + return filename + '.scss' + else: + return filename def build(self, package_dir, output_style='nested'): """Builds the Sass/SCSS files in the specified :attr:`sass_path`. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy