summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRocky Meza <rocky@fusionbox.com>2014-02-03 19:35:55 -0700
committerRocky Meza <rocky@fusionbox.com>2014-02-03 19:36:27 -0700
commit6b2ea386888c57b38001ec80442cc5b8096f9117 (patch)
treef0614f592d66bac6b44025921d67d350450aea91
parent53d023e45357516840ff28fa30df98ce14639111 (diff)
downloaddjango-pyscss-6b2ea386888c57b38001ec80442cc5b8096f9117.tar.gz
Added support for extensionless imports.
-rw-r--r--django_pyscss/scss.py24
-rw-r--r--testproject/testproject/static/css/css_file.css3
-rw-r--r--testproject/testproject/static/css/sass_file.sass2
-rw-r--r--tests/test_scss.py21
4 files changed, 43 insertions, 7 deletions
diff --git a/django_pyscss/scss.py b/django_pyscss/scss.py
index 3423b2c..1185f10 100644
--- a/django_pyscss/scss.py
+++ b/django_pyscss/scss.py
@@ -28,6 +28,8 @@ class DjangoScss(Scss):
A subclass of the Scss compiler that uses the storages API for accessing
files.
"""
+ supported_extensions = ['.scss', '.sass', '.css']
+
def get_file_from_storage(self, filename):
try:
filename = staticfiles_storage.path(filename)
@@ -47,19 +49,27 @@ class DjangoScss(Scss):
else:
return self.get_file_from_storage(filename)
- def get_possible_import_paths(self, filename, relative_to=None):
+ def get_possible_import_paths(self, path, relative_to=None):
"""
- Returns an iterable of possible filenames for an import.
+ Returns an iterable of possible paths for an import.
relative_to is None in the case that the SCSS is being rendered from a
string or if it is the first file.
"""
- if filename.startswith('/'): # absolute import
- filename = filename[1:]
- elif relative_to: # relative import
- filename = os.path.join(relative_to, filename)
+ paths = []
- return [filename]
+ if path.startswith('/'): # absolute import
+ path = path[1:]
+ elif relative_to: # relative import
+ path = os.path.join(relative_to, path)
+ paths.append(path)
+
+ dirname, filename = os.path.split(path)
+ name, ext = os.path.splitext(filename)
+ if not ext:
+ for extension in self.supported_extensions:
+ paths.append(os.path.join(dirname, name + extension))
+ return paths
def _find_source_file(self, filename, relative_to=None):
for name in self.get_possible_import_paths(filename, relative_to):
diff --git a/testproject/testproject/static/css/css_file.css b/testproject/testproject/static/css/css_file.css
new file mode 100644
index 0000000..0a9c27e
--- /dev/null
+++ b/testproject/testproject/static/css/css_file.css
@@ -0,0 +1,3 @@
+.css {
+ color: #001100;
+}
diff --git a/testproject/testproject/static/css/sass_file.sass b/testproject/testproject/static/css/sass_file.sass
new file mode 100644
index 0000000..fb03d35
--- /dev/null
+++ b/testproject/testproject/static/css/sass_file.sass
@@ -0,0 +1,2 @@
+.sass
+ color: #009900
diff --git a/tests/test_scss.py b/tests/test_scss.py
index d538068..e7f6fbd 100644
--- a/tests/test_scss.py
+++ b/tests/test_scss.py
@@ -17,6 +17,15 @@ with open(os.path.join(settings.BASE_DIR, 'testapp1', 'static', 'css', 'app1.scs
APP2_CONTENTS = FOO_CONTENTS + APP1_CONTENTS
+SASS_CONTENTS = """
+.sass {
+ color: #009900;
+}
+"""
+
+with open(os.path.join(settings.BASE_DIR, 'testproject', 'static', 'css', 'css_file.css')) as f:
+ CSS_CONTENTS = f.read()
+
class CompilerTestMixin(object):
def setUp(self):
@@ -56,6 +65,18 @@ class ImportTestMixin(CompilerTestMixin):
actual = self.compiler.compile(scss_string='@import "this-file-does-not-and-should-never-exist.scss";')
self.assertEqual(clean_css(actual), '')
+ def test_no_extension_import(self):
+ actual = self.compiler.compile(scss_string='@import "/css/foo";')
+ self.assertEqual(clean_css(actual), clean_css(FOO_CONTENTS))
+
+ def test_no_extension_import_sass(self):
+ actual = self.compiler.compile(scss_string='@import "/css/sass_file";')
+ self.assertEqual(clean_css(actual), clean_css(SASS_CONTENTS))
+
+ def test_no_extension_import_css(self):
+ actual = self.compiler.compile(scss_string='@import "/css/css_file";')
+ self.assertEqual(clean_css(actual), clean_css(CSS_CONTENTS))
+
@override_settings(DEBUG=True)
class FindersImportTest(ImportTestMixin, TestCase):