allow dots in filenames

This commit is contained in:
PhilipGarnero
2015-07-11 21:50:07 +02:00
committed by Philip Garnero
parent a48118f580
commit 57d006ba35
4 changed files with 25 additions and 6 deletions

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
.scss {
color: #009900;
}

View File

@@ -0,0 +1 @@
@import '../baz'

View File

@@ -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