diff options
author | PhilipGarnero <philip.garnero@gmail.com> | 2015-07-11 21:50:07 +0200 |
---|---|---|
committer | Philip Garnero <philip.garnero@corp.ovh.com> | 2015-07-17 17:41:12 +0200 |
commit | 57d006ba359a9f182a8545fc6ec689e5edca6102 (patch) | |
tree | 814c2ebf05e891c6496e3dbad92f1eac151544d5 | |
parent | a48118f5805b62c3c5fe6ada8340ba1a129e8ce9 (diff) | |
download | django-pyscss-57d006ba359a9f182a8545fc6ec689e5edca6102.tar.gz |
allow dots in filenames
-rw-r--r-- | django_pyscss/extension/django.py | 13 | ||||
-rw-r--r-- | testproject/testproject/static/css/dot.file.scss | 3 | ||||
-rw-r--r-- | testproject/testproject/static/css/sub/from_parent.scss | 1 | ||||
-rw-r--r-- | tests/test_scss.py | 14 |
4 files changed, 25 insertions, 6 deletions
diff --git a/django_pyscss/extension/django.py b/django_pyscss/extension/django.py index c388940..8db6ae1 100644 --- a/django_pyscss/extension/django.py +++ b/django_pyscss/extension/django.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, unicode_literals +import os + from itertools import product from pathlib import PurePath @@ -19,10 +21,11 @@ class DjangoExtension(CoreExtension): """ original_path = PurePath(name) - if original_path.suffix: - search_exts = [original_path.suffix] + search_exts = list(compilation.compiler.dynamic_extensions) + if original_path.suffix and original_path.suffix in search_exts: + basename = original_path.stem else: - search_exts = compilation.compiler.dynamic_extensions + basename = original_path.name if original_path.is_absolute(): # Remove the beginning slash @@ -30,12 +33,10 @@ class DjangoExtension(CoreExtension): elif rule.source_file.origin: search_path = rule.source_file.origin if original_path.parent: - search_path = search_path / original_path.parent + search_path = os.path.normpath(str(search_path / original_path.parent)) else: search_path = original_path.parent - basename = original_path.stem - for prefix, suffix in product(('_', ''), search_exts): filename = PurePath(prefix + basename + suffix) diff --git a/testproject/testproject/static/css/dot.file.scss b/testproject/testproject/static/css/dot.file.scss new file mode 100644 index 0000000..3cd0fe9 --- /dev/null +++ b/testproject/testproject/static/css/dot.file.scss @@ -0,0 +1,3 @@ +.scss { + color: #009900; +}
\ No newline at end of file diff --git a/testproject/testproject/static/css/sub/from_parent.scss b/testproject/testproject/static/css/sub/from_parent.scss new file mode 100644 index 0000000..37a9687 --- /dev/null +++ b/testproject/testproject/static/css/sub/from_parent.scss @@ -0,0 +1 @@ +@import '../baz'
\ No newline at end of file diff --git a/tests/test_scss.py b/tests/test_scss.py index f76b3e7..c1410e1 100644 --- a/tests/test_scss.py +++ b/tests/test_scss.py @@ -40,6 +40,9 @@ BAZ_CONTENTS = BAZ_CONTENTS.replace('@import "sub/spam";', SPAM_CONTENTS) with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'path_conflict.scss')) as f: PATH_CONFLICT_CONTENTS = f.read() +with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'dot.file.scss')) as f: + DOT_FILE_CONTENTS = f.read() + class CompilerTestMixin(object): def setUp(self): @@ -103,6 +106,17 @@ class ImportTestMixin(CompilerTestMixin): actual = self.compiler.compile_string('@import "/css/path_conflict";') self.assertEqual(clean_css(actual), clean_css(PATH_CONFLICT_CONTENTS)) + def test_import_dots_without_extension(self): + actual = self.compiler.compile_string('@import "/css/dot.file";') + self.assertEqual(clean_css(actual), clean_css(DOT_FILE_CONTENTS)) + + def test_import_dots_with_extension(self): + actual = self.compiler.compile_string('@import "/css/dot.file.scss";') + self.assertEqual(clean_css(actual), clean_css(DOT_FILE_CONTENTS)) + + def test_import_from_parent(self): + actual = self.compiler.compile_string('@import "/css/sub/from_parent";') + self.assertEqual(clean_css(actual), clean_css(BAZ_CONTENTS)) class FindersImportTest(ImportTestMixin, NoCollectStaticTestCase): pass |