Skip to content

Commit

Permalink
Fix recursive subdirectory build bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Sep 23, 2014
1 parent d562156 commit e09f32d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ To be released.
- Fixed a bug that :class:`~sassutils.wsgi.SassMiddleware` yielded
:class:`str` instead of :class:`bytes` on Python 3.
- Fixed several Unicode-related bugs on Windows.
- Fixed a bug that :func:`~sassutils.builder.build_directory()`,
:class:`~sassutils.wsgi.SassMiddleware`, and
:class:`~sassutils.distutils.build_sass` don't recursively build
subdirectories.


Version 0.5.0
Expand Down
13 changes: 12 additions & 1 deletion sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
font: '나눔고딕', sans-serif; }
'''

SUBDIR_RECUR_EXPECTED_CSS = '''\
body p {
color: blue; }
'''

utf8_if_py3 = {'encoding': 'utf-8'} if PY3 else {}


Expand Down Expand Up @@ -229,7 +234,7 @@ def test_builder_build_directory(self):
css_path = os.path.join(temp_path, 'css')
shutil.copytree('test', sass_path)
result_files = build_directory(sass_path, css_path)
assert len(result_files) == 4
assert len(result_files) == 5
assert result_files['a.scss'] == 'a.scss.css'
with open(os.path.join(css_path, 'a.scss.css'), **utf8_if_py3) as f:
css = f.read()
Expand All @@ -246,6 +251,12 @@ def test_builder_build_directory(self):
with open(os.path.join(css_path, 'd.scss.css'), **utf8_if_py3) as f:
css = f.read()
self.assertEqual(D_EXPECTED_CSS, css)
assert (result_files[os.path.join('subdir', 'recur.scss')] ==
os.path.join('subdir', 'recur.scss.css'))
with open(os.path.join(css_path, 'subdir', 'recur.scss.css'),
**utf8_if_py3) as f:
css = f.read()
self.assertEqual(SUBDIR_RECUR_EXPECTED_CSS, css)
shutil.rmtree(temp_path)


Expand Down
4 changes: 1 addition & 3 deletions sassutils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ def build_directory(sass_path, css_path, _root_sass=None, _root_css=None):
if not os.path.isdir(css_path):
os.mkdir(css_path)
for name in os.listdir(sass_path):
if not SUFFIX_PATTERN.search(name):
continue
sass_fullname = os.path.join(sass_path, name)
if os.path.isfile(sass_fullname):
if SUFFIX_PATTERN.search(name) and os.path.isfile(sass_fullname):
css_fullname = os.path.join(css_path, name) + '.css'
css = compile(filename=sass_fullname, include_paths=[_root_sass])
with io.open(css_fullname, 'w', encoding='utf-8') as css_file:
Expand Down
4 changes: 4 additions & 0 deletions test/subdir/recur.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

body {
p { color: blue; }
}

0 comments on commit e09f32d

Please sign in to comment.