allow dots in filenames
This commit is contained in:
committed by
Philip Garnero
parent
a48118f580
commit
57d006ba35
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from pathlib import PurePath
|
from pathlib import PurePath
|
||||||
|
|
||||||
@@ -19,10 +21,11 @@ class DjangoExtension(CoreExtension):
|
|||||||
"""
|
"""
|
||||||
original_path = PurePath(name)
|
original_path = PurePath(name)
|
||||||
|
|
||||||
if original_path.suffix:
|
search_exts = list(compilation.compiler.dynamic_extensions)
|
||||||
search_exts = [original_path.suffix]
|
if original_path.suffix and original_path.suffix in search_exts:
|
||||||
|
basename = original_path.stem
|
||||||
else:
|
else:
|
||||||
search_exts = compilation.compiler.dynamic_extensions
|
basename = original_path.name
|
||||||
|
|
||||||
if original_path.is_absolute():
|
if original_path.is_absolute():
|
||||||
# Remove the beginning slash
|
# Remove the beginning slash
|
||||||
@@ -30,12 +33,10 @@ class DjangoExtension(CoreExtension):
|
|||||||
elif rule.source_file.origin:
|
elif rule.source_file.origin:
|
||||||
search_path = rule.source_file.origin
|
search_path = rule.source_file.origin
|
||||||
if original_path.parent:
|
if original_path.parent:
|
||||||
search_path = search_path / original_path.parent
|
search_path = os.path.normpath(str(search_path / original_path.parent))
|
||||||
else:
|
else:
|
||||||
search_path = original_path.parent
|
search_path = original_path.parent
|
||||||
|
|
||||||
basename = original_path.stem
|
|
||||||
|
|
||||||
for prefix, suffix in product(('_', ''), search_exts):
|
for prefix, suffix in product(('_', ''), search_exts):
|
||||||
filename = PurePath(prefix + basename + suffix)
|
filename = PurePath(prefix + basename + suffix)
|
||||||
|
|
||||||
|
|||||||
3
testproject/testproject/static/css/dot.file.scss
Normal file
3
testproject/testproject/static/css/dot.file.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.scss {
|
||||||
|
color: #009900;
|
||||||
|
}
|
||||||
1
testproject/testproject/static/css/sub/from_parent.scss
Normal file
1
testproject/testproject/static/css/sub/from_parent.scss
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@import '../baz'
|
||||||
@@ -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:
|
with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'path_conflict.scss')) as f:
|
||||||
PATH_CONFLICT_CONTENTS = f.read()
|
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):
|
class CompilerTestMixin(object):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -103,6 +106,17 @@ class ImportTestMixin(CompilerTestMixin):
|
|||||||
actual = self.compiler.compile_string('@import "/css/path_conflict";')
|
actual = self.compiler.compile_string('@import "/css/path_conflict";')
|
||||||
self.assertEqual(clean_css(actual), clean_css(PATH_CONFLICT_CONTENTS))
|
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):
|
class FindersImportTest(ImportTestMixin, NoCollectStaticTestCase):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user