Skip to content

Commit 1a711e2

Browse files
authored
Merge pull request sass#278 from asottile/sass_extension_wsgi_middleware
Support .sass extension for the wsgi middleware
2 parents 8f91684 + 8f1056a commit 1a711e2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

sasstests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,32 @@ def test_wsgi_sass_middleware_without_extension(self):
752752
self.assertEqual(expected.encode(), r.data)
753753
assert r.mimetype == 'text/css'
754754

755+
def test_wsgi_sass_middleware_without_extension_sass(self):
756+
with tempdir() as css_dir:
757+
src_dir = os.path.join(css_dir, 'src')
758+
os.makedirs(src_dir)
759+
with open(os.path.join(src_dir, 'a.sass'), 'w') as f:
760+
f.write('a\n\tb\n\t\tcolor: blue;')
761+
app = SassMiddleware(
762+
self.sample_wsgi_app, {
763+
__name__: {
764+
'sass_path': src_dir,
765+
'css_path': css_dir,
766+
'wsgi_path': '/static',
767+
'strip_extension': True,
768+
},
769+
},
770+
)
771+
client = Client(app, Response)
772+
r = client.get('/static/a.css')
773+
assert r.status_code == 200
774+
expected = (
775+
'a b {\n color: blue; }\n\n'
776+
'/*# sourceMappingURL=../a.css.map */'
777+
)
778+
self.assertEqual(expected.encode(), r.data)
779+
assert r.mimetype == 'text/css'
780+
755781

756782
class DistutilsTestCase(BaseTestCase):
757783

sassutils/builder.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,14 @@ def unresolve_filename(self, filename):
199199
"""
200200
filename, _ = os.path.splitext(filename)
201201
if self.strip_extension:
202-
filename = filename + '.scss'
203-
return filename
202+
for ext in ('.scss', '.sass'):
203+
test_path = os.path.join(self.sass_path, filename + ext)
204+
if os.path.exists(test_path):
205+
return filename + ext
206+
else: # file not found, let it error with `.scss` extension
207+
return filename + '.scss'
208+
else:
209+
return filename
204210

205211
def build(self, package_dir, output_style='nested'):
206212
"""Builds the Sass/SCSS files in the specified :attr:`sass_path`.

0 commit comments

Comments
 (0)
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