Skip to content

Commit

Permalink
Revert "build: import XModule source SCSS directly rather than copying (
Browse files Browse the repository at this point in the history
#32289)"

This reverts commit 3fab0ae.
  • Loading branch information
kdmccormick authored Jun 14, 2023
1 parent 3fab0ae commit 929b7a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
10 changes: 2 additions & 8 deletions pavelib/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def get_theme_sass_dirs(system, theme_dir):
certs_css_dir = theme_dir / system / "static" / "certificates" / "css"
xmodule_sass_folder = "modules" if system == 'lms' else "descriptors"
xmodule_sass_dir = path("common") / "static" / "xmodule" / xmodule_sass_folder / "scss"
xmodule_lookup_dir = path("xmodule") / "css"

dependencies = SASS_LOOKUP_DEPENDENCIES.get(system, [])
if sass_dir.isdir():
Expand Down Expand Up @@ -203,9 +202,7 @@ def get_theme_sass_dirs(system, theme_dir):
dirs.append({
"sass_source_dir": xmodule_sass_dir,
"css_destination_dir": path("common") / "static" / "css" / "xmodule",
"lookup_paths": [
xmodule_lookup_dir,
*dependencies,
"lookup_paths": dependencies + [
sass_dir / "partials",
system_sass_dir / "partials",
system_sass_dir,
Expand Down Expand Up @@ -240,7 +237,6 @@ def get_system_sass_dirs(system):
css_dir = path(system) / "static" / "css"
xmodule_sass_folder = "modules" if system == 'lms' else "descriptors"
xmodule_sass_dir = path("common") / "static" / "xmodule" / xmodule_sass_folder / "scss"
xmodule_lookup_dir = path("xmodule") / "css"

dependencies = SASS_LOOKUP_DEPENDENCIES.get(system, [])
dirs.append({
Expand All @@ -255,9 +251,7 @@ def get_system_sass_dirs(system):
dirs.append({
"sass_source_dir": xmodule_sass_dir,
"css_destination_dir": path("common") / "static" / "css" / "xmodule",
"lookup_paths": [
xmodule_lookup_dir,
*dependencies,
"lookup_paths": dependencies + [
sass_dir / "partials",
sass_dir,
],
Expand Down
21 changes: 15 additions & 6 deletions xmodule/static_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,29 @@ def _write_styles(selector, output_root, classes, css_attribute, suffix):
into `output_root` as individual files
"""
contents = {}
xmodule_scss_path = resource_filename(__name__, "") + "/css/"

for class_ in classes:
class_css = getattr(class_, css_attribute)()
rel_fragment_paths = []
for fragment_path in class_css.get('scss', []):
rel_fragment_path = fragment_path.split(xmodule_scss_path)[1]
rel_fragment_paths.append(rel_fragment_path)
fragment_paths = class_css.get('scss', [])
if not fragment_paths:
continue
fragment_names = []
for fragment_path in fragment_paths:
with open(fragment_path, 'rb') as fragment_file:
fragment = fragment_file.read()
fragment_name = "{hash}.{type}".format(
hash=hashlib.md5(fragment).hexdigest(),
type='scss')
# Prepend _ so that sass just includes the files into a single file
filename = '_' + fragment_name
contents[filename] = fragment
fragment_names.append(fragment_name)

module_styles_lines = []
module_styles_lines.append("""{selector}.xmodule_{class_.__name__} {{""".format(
class_=class_, selector=selector
))
module_styles_lines.extend(f' @import "{path}";' for path in rel_fragment_paths)
module_styles_lines.extend(f' @import "{name}";' for name in fragment_names)
module_styles_lines.append('}')

contents[f"{class_.__name__}{suffix}.scss"] = '\n'.join(module_styles_lines)
Expand Down

0 comments on commit 929b7a8

Please sign in to comment.