Skip to content

Commit 57d006b

Browse files
committed
allow dots in filenames
1 parent a48118f commit 57d006b

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

django_pyscss/extension/django.py

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

3+
import os
4+
35
from itertools import product
46
from pathlib import PurePath
57

@@ -19,23 +21,22 @@ def handle_import(self, name, compilation, rule):
1921
"""
2022
original_path = PurePath(name)
2123

22-
if original_path.suffix:
23-
search_exts = [original_path.suffix]
24+
search_exts = list(compilation.compiler.dynamic_extensions)
25+
if original_path.suffix and original_path.suffix in search_exts:
26+
basename = original_path.stem
2427
else:
25-
search_exts = compilation.compiler.dynamic_extensions
28+
basename = original_path.name
2629

2730
if original_path.is_absolute():
2831
# Remove the beginning slash
2932
search_path = original_path.relative_to('/').parent
3033
elif rule.source_file.origin:
3134
search_path = rule.source_file.origin
3235
if original_path.parent:
33-
search_path = search_path / original_path.parent
36+
search_path = os.path.normpath(str(search_path / original_path.parent))
3437
else:
3538
search_path = original_path.parent
3639

37-
basename = original_path.stem
38-
3940
for prefix, suffix in product(('_', ''), search_exts):
4041
filename = PurePath(prefix + basename + suffix)
4142

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scss {
2+
color: #009900;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import '../baz'

tests/test_scss.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'path_conflict.scss')) as f:
4141
PATH_CONFLICT_CONTENTS = f.read()
4242

43+
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'dot.file.scss')) as f:
44+
DOT_FILE_CONTENTS = f.read()
45+
4346

4447
class CompilerTestMixin(object):
4548
def setUp(self):
@@ -103,6 +106,17 @@ def test_import_conflict(self):
103106
actual = self.compiler.compile_string('@import "/css/path_conflict";')
104107
self.assertEqual(clean_css(actual), clean_css(PATH_CONFLICT_CONTENTS))
105108

109+
def test_import_dots_without_extension(self):
110+
actual = self.compiler.compile_string('@import "/css/dot.file";')
111+
self.assertEqual(clean_css(actual), clean_css(DOT_FILE_CONTENTS))
112+
113+
def test_import_dots_with_extension(self):
114+
actual = self.compiler.compile_string('@import "/css/dot.file.scss";')
115+
self.assertEqual(clean_css(actual), clean_css(DOT_FILE_CONTENTS))
116+
117+
def test_import_from_parent(self):
118+
actual = self.compiler.compile_string('@import "/css/sub/from_parent";')
119+
self.assertEqual(clean_css(actual), clean_css(BAZ_CONTENTS))
106120

107121
class FindersImportTest(ImportTestMixin, NoCollectStaticTestCase):
108122
pass

0 commit comments

Comments
 (0)