Skip to content

Commit

Permalink
Merge pull request #278 from asottile/sass_extension_wsgi_middleware
Browse files Browse the repository at this point in the history
Support .sass extension for the wsgi middleware
  • Loading branch information
asottile authored Nov 25, 2018
2 parents 8f91684 + 8f1056a commit 1a711e2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
26 changes: 26 additions & 0 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
10 changes: 8 additions & 2 deletions sassutils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 1a711e2

Please sign in to comment.