Skip to content

Commit 8eedaa6

Browse files
authored
Merge pull request #260 from lunkwill42/strip-extensions-from-build-directory
Honor strip_extension option when building entire directory structures from distutils
2 parents cca5f11 + b295802 commit 8eedaa6

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

sasstests.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def replace_source_path(s, name):
635635
)
636636

637637

638-
def test_manifest_strip_extension(tmpdir):
638+
def test_manifest_build_one_strip_extension(tmpdir):
639639
src = tmpdir.join('test').ensure_dir()
640640
src.join('a.scss').write('a{b: c;}')
641641

@@ -645,6 +645,16 @@ def test_manifest_strip_extension(tmpdir):
645645
assert tmpdir.join('css/a.css').read() == 'a {\n b: c; }\n'
646646

647647

648+
def test_manifest_build_strip_extension(tmpdir):
649+
src = tmpdir.join('test').ensure_dir()
650+
src.join('x.scss').write('a{b: c;}')
651+
652+
m = Manifest(sass_path='test', css_path='css', strip_extension=True)
653+
m.build(package_dir=str(tmpdir))
654+
655+
assert tmpdir.join('css/x.css').read() == 'a {\n b: c; }\n'
656+
657+
648658
class WsgiTestCase(BaseTestCase):
649659

650660
@staticmethod

sassutils/builder.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def build_directory(sass_path, css_path, output_style='nested',
30-
_root_sass=None, _root_css=None):
30+
_root_sass=None, _root_css=None, strip_extension=False):
3131
"""Compiles all Sass/SCSS files in ``path`` to CSS.
3232
3333
:param sass_path: the path of the directory which contains source files
@@ -58,6 +58,8 @@ def build_directory(sass_path, css_path, output_style='nested',
5858
if name[0] == '_':
5959
# Do not compile if it's partial
6060
continue
61+
if strip_extension:
62+
name, _ = os.path.splitext(name)
6163
css_fullname = os.path.join(css_path, name) + '.css'
6264
css = compile(filename=sass_fullname,
6365
output_style=output_style,
@@ -73,7 +75,8 @@ def build_directory(sass_path, css_path, output_style='nested',
7375
subresult = build_directory(sass_fullname, css_fullname,
7476
output_style=output_style,
7577
_root_sass=_root_sass,
76-
_root_css=_root_css)
78+
_root_css=_root_css,
79+
strip_extension=strip_extension)
7780
result.update(subresult)
7881
return result
7982

@@ -201,7 +204,8 @@ def build(self, package_dir, output_style='nested'):
201204
css_path = os.path.join(package_dir, self.css_path)
202205
css_files = build_directory(
203206
sass_path, css_path,
204-
output_style=output_style
207+
output_style=output_style,
208+
strip_extension=self.strip_extension
205209
).values()
206210
return frozenset(os.path.join(self.css_path, filename)
207211
for filename in css_files)

0 commit comments

Comments
 (0)