Skip to content

Commit 92d58f9

Browse files
committed
Honor strip_extension in SassMiddleware
1 parent 4781031 commit 92d58f9

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

sasstests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,27 @@ def test_wsgi_sass_middleware(self):
731731
self.assertEqual(b'/static/not-exists.sass.css', r.data)
732732
assert r.mimetype == 'text/plain'
733733

734+
def test_wsgi_sass_middleware_without_extension(self):
735+
with tempdir() as css_dir:
736+
src_dir = os.path.join(css_dir, 'src')
737+
shutil.copytree('test', src_dir)
738+
app = SassMiddleware(
739+
self.sample_wsgi_app, {
740+
__name__: {
741+
'sass_path': src_dir,
742+
'css_path': css_dir,
743+
'wsgi_path': '/static',
744+
'strip_extension': True,
745+
},
746+
},
747+
)
748+
client = Client(app, Response)
749+
r = client.get('/static/a.css')
750+
assert r.status_code == 200
751+
expected = A_EXPECTED_CSS_WITH_MAP.replace('.scss.css', '.css')
752+
self.assertEqual(expected.encode(), r.data)
753+
assert r.mimetype == 'text/css'
754+
734755

735756
class DistutilsTestCase(BaseTestCase):
736757

sassutils/builder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ def resolve_filename(self, package_dir, filename):
188188
css_path = os.path.join(package_dir, self.css_path, css_filename)
189189
return sass_path, css_path
190190

191+
def unresolve_filename(self, filename):
192+
"""Retrieves the probable source path from the output filename. Pass
193+
in a .css path to get out a .scss path.
194+
195+
:param filename: the css filename
196+
:type filename: :class:`str`
197+
:returns: the scss filename
198+
:rtype: :class:`str`
199+
"""
200+
filename, _ = os.path.splitext(filename)
201+
if self.strip_extension:
202+
filename = filename + '.scss'
203+
return filename
204+
191205
def build(self, package_dir, output_style='nested'):
192206
"""Builds the Sass/SCSS files in the specified :attr:`sass_path`.
193207
It finds :attr:`sass_path` and locates :attr:`css_path`

sassutils/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __call__(self, environ, start_response):
125125
if not path.startswith(prefix):
126126
continue
127127
css_filename = path[len(prefix):]
128-
sass_filename = css_filename[:-4]
128+
sass_filename = manifest.unresolve_filename(css_filename)
129129
try:
130130
result = manifest.build_one(
131131
package_dir,

0 commit comments

Comments
 (0)