Skip to content

Commit e145016

Browse files
authored
Merge pull request #74 from lemonsaurus/lint-on-push
Support more than one custom SCSS file.
2 parents 484e0f9 + 0c57bb0 commit e145016

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

django_simple_bulma/finders.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ def __init__(self):
4444
self.output_style = self.bulma_settings.get("output_style", "nested")
4545
self.storage = FileSystemStorage(simple_bulma_path)
4646

47-
def _get_extension_imports(self) -> str:
47+
# Make a list of all the finders except this one.
48+
# We use this in the custom SCSS handler.
49+
other_finders = settings.STATICFILES_FINDERS.copy()
50+
other_finders.remove("django_simple_bulma.finders.SimpleBulmaFinder")
51+
self.other_finders = [get_finder(finder) for finder in other_finders]
52+
53+
@staticmethod
54+
def _get_extension_imports() -> str:
4855
"""Return a string that, in SASS, imports all enabled extensions."""
4956
scss_imports = ""
5057

@@ -56,13 +63,35 @@ def _get_extension_imports(self) -> str:
5663

5764
return scss_imports
5865

59-
def _unpack_variables(self, variables: dict) -> str:
66+
@staticmethod
67+
def _unpack_variables(variables: dict) -> str:
6068
"""Unpacks SASS variables from a dictionary to a compilable string."""
6169
scss_string = ""
6270
for var, value in variables.items():
6371
scss_string += f"${var}: {value};\n"
6472
return scss_string
6573

74+
@staticmethod
75+
def _get_bulma_js() -> List[str]:
76+
"""Return a list of all the js files that are needed for the users selected extensions."""
77+
return list(get_js_files())
78+
79+
@staticmethod
80+
def find_relative_staticfiles(path: Union[str, Path]) -> Union[Path, None]:
81+
"""
82+
Returns a given path, relative to one of the paths in STATICFILES_DIRS.
83+
84+
Returns None if the given path isn't available within STATICFILES_DIRS.
85+
"""
86+
if not isinstance(path, Path):
87+
path = Path(abspath(path))
88+
89+
for directory in settings.STATICFILES_DIRS:
90+
directory = Path(abspath(directory))
91+
92+
if directory in path.parents:
93+
return path.relative_to(directory)
94+
6695
def _get_bulma_css(self) -> List[str]:
6796
"""Compiles the bulma css files for each theme and returns their relative paths."""
6897
# If the user has the sass module installed in addition to libsass,
@@ -132,12 +161,8 @@ def _get_custom_css(self) -> str:
132161
relative_path = scss_path.split("static/", 1)[-1]
133162

134163
# Check that we can find this file with one of the other finders.
135-
other_finders = settings.STATICFILES_FINDERS
136-
other_finders.remove("django_simple_bulma.finders.SimpleBulmaFinder")
137-
other_finders = [get_finder(finder) for finder in other_finders]
138164
absolute_path = None
139-
140-
for finder in other_finders:
165+
for finder in self.other_finders:
141166
if absolute_path := finder.find(relative_path):
142167
break
143168

@@ -172,26 +197,6 @@ def _get_custom_css(self) -> str:
172197

173198
return paths
174199

175-
def _get_bulma_js(self) -> List[str]:
176-
"""Return a list of all the js files that are needed for the users selected extensions."""
177-
return list(get_js_files())
178-
179-
@staticmethod
180-
def find_relative_staticfiles(path: Union[str, Path]) -> Union[Path, None]:
181-
"""
182-
Returns a given path, relative to one of the paths in STATICFILES_DIRS.
183-
184-
Returns None if the given path isn't available within STATICFILES_DIRS.
185-
"""
186-
if not isinstance(path, Path):
187-
path = Path(abspath(path))
188-
189-
for directory in settings.STATICFILES_DIRS:
190-
directory = Path(abspath(directory))
191-
192-
if directory in path.parents:
193-
return path.relative_to(directory)
194-
195200
def find(self, path: str, all: bool = False) -> Union[List[str], str]:
196201
"""
197202
Given a relative file path, find an absolute file path.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="django-simple-bulma",
12-
version="2.3.0",
12+
version="2.3.1",
1313
description="Django application to add the Bulma CSS framework and its extensions",
1414
long_description=open("README.md").read(),
1515
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)