Skip to content

Commit 2c19475

Browse files
author
Rocky Meza
committed
Added support for underscore imports.
1 parent dc0e8a8 commit 2c19475

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

django_pyscss/scss.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import, unicode_literals
22

33
import os
4+
from itertools import product
45

56
from django.contrib.staticfiles.storage import staticfiles_storage
67
from django.conf import settings
@@ -70,9 +71,12 @@ def get_possible_import_paths(self, path, relative_to=None):
7071

7172
dirname, filename = os.path.split(path)
7273
name, ext = os.path.splitext(filename)
73-
if not ext:
74-
for extension in self.supported_extensions:
75-
paths.append(os.path.join(dirname, name + extension))
74+
if ext:
75+
search_exts = [ext]
76+
else:
77+
search_exts = self.supported_extensions
78+
for prefix, suffix in product(('_', ''), search_exts):
79+
paths.append(os.path.join(dirname, prefix + name + suffix))
7680
return paths
7781

7882
def _find_source_file(self, filename, relative_to=None):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.baz {
2+
color: #123456;
3+
}

tests/test_scss.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'css_file.css')) as f:
2727
CSS_CONTENTS = f.read()
2828

29+
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', '_baz.scss')) as f:
30+
BAZ_CONTENTS = f.read()
31+
2932

3033
class CompilerTestMixin(object):
3134
def setUp(self):
@@ -77,6 +80,10 @@ def test_no_extension_import_css(self):
7780
actual = self.compiler.compile(scss_string='@import "/css/css_file";')
7881
self.assertEqual(clean_css(actual), clean_css(CSS_CONTENTS))
7982

83+
def test_import_underscore_file(self):
84+
actual = self.compiler.compile(scss_string='@import "/css/baz";')
85+
self.assertEqual(clean_css(actual), clean_css(BAZ_CONTENTS))
86+
8087

8188
@override_settings(DEBUG=True)
8289
class FindersImportTest(ImportTestMixin, TestCase):

0 commit comments

Comments
 (0)