forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make built-in XBlock Sass theme-aware again
In ~Palm and earlier, all built-in XBlock Sass was included into LMS and CMS styles before being compiled. The generated CSS was coupled together with broader LMS/CMS CSS. This means that comprehensive themes have been able to modify built-in XBlock appearance by setting certain Sass variables. We say that built-in XBlock Sass was, and is expected to be, "theme-aware". Shortly after Palm, we decoupled XBlock Sass from LMS and CMS Sass [1]. Each built-in block's Sass is now compiled into two separate CSS targets, one for block editing and one for block display. The CSS, now located at `common/static/css/xmodule`, is injected into the running Webpack context with the new `XModuleWebpackLoader`. Built-in XBlocks already used `add_webpack_to_fragment` in order to add JS Webpack bundles to their view fragments, so when CSS was added to Webpack, it Just Worked. This unlocked a slieu of simplifications for static asset processing [2]; however, it accidentally made XBlock Sass theme-*unaware*, or perhaps theme-confused, since the CSS was targeted at `common/static/css/xmodule` regardless of the theme. The result of this is that **built-in XBlock views will use CSS based on the Sass variables _last theme to be compiled._** Sass variables are only used in a handful of places in XBlocks, so the bug is subtle, but it is there for those running off of master. For example, using edX.org's theme on master, we can see that there is a default blue underline in the Studio sequence nav [3]. With this bugfix, it becomes the standard edX.org greenish-black [4]. This commit makes several changes, firstly to fix the bug, and secondly to leave ourselves with a more comprehensible asset setup in the `xmodule/` directory. * We remove the `XModuleWebpackLoader`, thus taking built-in XBlock Sass back out of Webpack. * We compile XBlock Sass not to `common/static/css/xmodule`, but to: * `[lms|cms]/static/css` for the default theme, and * `<THEME_ROOT>/[lms|cms]/static/css`, for any custom theme. This is where the comprehensive theming system expects to find themable assets. Unfortunately, this does mean that the Sass is compiled twice, both for LMS and CMS. We would have liked to compile it once to somewhere in the `common/`, but comprehensive theming does not consider `common/` assets to be themable. * We split `add_webpack_to_fragment` into two more specialized functions: * `add_webpack_js_to_fragment` , for adding *just* JS from a Webpack bundle, and * `add_sass_to_fragment`, for adding static links to CSS compiled themable Sass (not Webpack). Both these functions are moved to a new module `xmodule/util/builtin_assets.py`, since the original module (`xmodule/util/xmodule_django.py`) didn't make a ton of sense. * In an orthogonal bugfix, we merge Sass `CourseInfoBlock`, `StaticTabBlock`, `AboutBlock` into the `HtmlBlock` Sass files. The first three were never used, as their styling was handled by `HtmlBlock` (their shared parent class). * As a refactoring, we change Webpack bundle names and Sass module names to be less misleading: * student_view, public_view, and author_view: was `<Name>BlockPreview`, is now `<Name>BlockDisplay`. * studio_view: was `<Name>BlockStudio`, is now `<Name>BlockEditor`. * As a refactoring, we move the contents of `xmodule/static` into the existing `xmodule/assets` directory, and adopt its simper structure. We now have: * `xmodule/assets/*.scss`: Top-level compiled Sass modules. These could be collapsed away in a future refactoring. * `xmodule/assets/<blocktype>/*`: Resources for each block, including both JS modules and Sass includes (underscore-prefixed so that they aren't compiled). This structure maps closely with what externally-defined XBlocks do. * `xmodule/js` still exists, but it will soon be folded into the `xmodule/assets`. * We add a new README [4] to explain the new structure, and also update a docstring in `openedx/lib/xblock/utils` which had fallen out of date with reality. * Side note: We avoid the term "XModule" in all of this, because that's (thankfully) become a much less useful/accurate way to describe these blocks. Instead, we say "built-in XBlocks". Refs: 1. openedx#32018 2. openedx#32292 3. https://github.com/openedx/edx-platform/assets/3628148/8b44545d-0f71-4357-9385-69d6e1cca86f 4. https://github.com/openedx/edx-platform/assets/3628148/d0b7b309-b8a4-4697-920a-8a520e903e06 5. https://github.com/openedx/edx-platform/tree/master/xmodule/assets#readme Part of: openedx#32292
- Loading branch information
1 parent
ab3d322
commit 5f05232
Showing
61 changed files
with
355 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.xmodule_display.xmodule_AboutBlock, | ||
.xmodule_display.xmodule_CourseInfoBlock, | ||
.xmodule_display.xmodule_HtmlBlock, | ||
.xmodule_display.xmodule_StaticTabBlock { | ||
@import "html/display.scss"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.xmodule_edit.xmodule_AboutBlock, | ||
.xmodule_edit.xmodule_CourseInfoBlock, | ||
.xmodule_edit.xmodule_HtmlBlock, | ||
.xmodule_edit.xmodule_StaticTabBlock { | ||
@import "editor/edit.scss"; | ||
@import "html/edit.scss"; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
xmodule/assets: edx-platform XBlock resources | ||
############################################# | ||
|
||
This folder exists to contain resources (ie, static assets) for the XBlocks | ||
defined in edx-platform. | ||
|
||
Concepts | ||
******** | ||
|
||
We would like edx-platform XBlock resources to match the standard XBlock | ||
resource strategy as much as possible, because: | ||
|
||
* it'll make it easier to extract the XBlocks into their own packages | ||
eventually, and | ||
* it makes it easier to reason about the system as a whole when | ||
internally-defined and externally-defined blocks play by the same rules. | ||
|
||
Due to the legacy of the XModule system, we're not quite there yet. | ||
However, we are proactively working towards a system where: | ||
|
||
* Python is not involved in the generation of static assets. | ||
* We minimze conditionals that differentiate between "older" (aka "XModule-style") | ||
XBlocks and newer (aka "pure") XBlocks. | ||
* Each XBlock's assets are contained within their own folder as much as | ||
possible. See ``./vertical`` as an example. | ||
|
||
Themable Sass (.scss) | ||
********************* | ||
|
||
XBlock CSS for ``student_view``, ``author_view``, and ``public_view`` is compiled from the various ``./<ClassName>BlockDisplay.scss`` modules, such as `AnnotatableBlockDisplay.scss`_. | ||
|
||
XBlock CSS for ``studio_view`` is compiled from the various ``./<ClassName>BlockEditor.scss`` modules, such as `AnnotatableBlockEditor.scss`_. | ||
|
||
Those Sass modules are mostly thin wrappers around the underscore-prefixed Sass | ||
modules within block-type-subdirectories, such as `annotatable/_display.css`. In the | ||
future, we may `simplify things`_ by collapsing the top-level Sass modules and | ||
just directly compiling the block-type-subdirectories' Sass. | ||
|
||
The CSS is compiled into the static folders of both LMS and CMS, as well as into | ||
the corresponding folders in any enabled themes, as part of the edx-platform build. | ||
It is collected into the static root, and then linked to from XBlock fragments by the | ||
``add_sass_to_fragment`` function in `builtin_assets.py`_. | ||
|
||
.. _AnnotatableBlockDisplay: https://github.com/openedx/edx-platform/tree/master/xmodule/assets/AnnotatableBlockDisplay.scss | ||
.. _AnnotatableBlockEditor: https://github.com/openedx/edx-platform/tree/master/xmodule/assets/AnnotatableBlockEditor.scss | ||
.. _annotatable/_display.scss: https://github.com/openedx/edx-platform/tree/master/xmodule/assets/annotatable/_display.scss | ||
.. _simplify things: https://github.com/openedx/edx-platform/issues/32621 | ||
|
||
Static CSS (.css) | ||
***************** | ||
|
||
Non-themable, ready-to-seve CSS may also be added to the any block type's | ||
subdirectory. For example, see `library_source_block/style.css`_. | ||
|
||
JavaScript (.js) | ||
**************** | ||
|
||
Currently, edx-platform XBlock JS is defined both here in `xmodule/assets`_ and outside in `xmodule/js`_. Different JS resources are processed differently: | ||
|
||
* For many older blocks, their JS is: | ||
|
||
* copied to ``common/static/xmodule`` by `static_content.py`_ (aka ``xmodule_assets``), | ||
* then bundled using a generated Webpack config at ``common/static/xmodule/webpack.xmodule.config.js``, | ||
* which is included into `webpack.common.config.js`_, | ||
* allowing it to be included into XBlock fragments using ``add_webpack_js_to_fragment`` from `builtin_assets.py`_. | ||
|
||
Example blocks using this setup: | ||
|
||
* `ProblemBlock`_ | ||
* `HtmlBlock`_ | ||
* `AnnotatableBlock`_ | ||
|
||
* For other "purer" blocks, the JS is used as a standard XBlock fragment. Example blocks: | ||
|
||
* `VerticalBlock`_ | ||
* `LibrarySourcedBlock`_ | ||
|
||
* Some XBlock JS is also processed through Django Pipeline and used in a couple specific legacy places. | ||
|
||
As part of an `active build refactoring`_: | ||
|
||
* We update the older builtin XBlocks to reference their JS directly rather than using copies of it. | ||
* We will move ``webpack.xmodule.config.js`` here instead of generating it. | ||
* We will consolidate all edx-platform XBlock JS here in `xmodule/assets`_. | ||
* We will remove XBlock JS from Django Pipeline. | ||
* We will delete the ``xmodule_assets`` script. | ||
|
||
.. _xmodule/assets: https://github.com/openedx/edx-platform/tree/master/xmodule/assets | ||
.. _xmodule/js: https://github.com/openedx/edx-platform/tree/master/xmodule/js | ||
.. _ProblemBlock: https://github.com/openedx/edx-platform/blob/master/xmodule/capa_block.py | ||
.. _HtmlBlock: https://github.com/openedx/edx-platform/blob/master/xmodule/html_block.py | ||
.. _AnnotatableBlock: https://github.com/openedx/edx-platform/blob/master/xmodule/annotatable_block.py | ||
.. _VerticalBlock: https://github.com/openedx/edx-platform/blob/master/xmodule/vertical_block.py | ||
.. _LibrarySourcedBlock: https://github.com/openedx/edx-platform/blob/master/xmodule/library_sourced_block.py | ||
.. _active build refactoring: https://github.com/openedx/edx-platform/issues/31624 | ||
.. _builtin_assets.py: https://github.com/openedx/edx-platform/tree/master/xmodule/util/builtin_assets.py | ||
.. _static_content.py: https://github.com/openedx/edx-platform/blob/master/xmodule/static_content.py | ||
.. _library_source_block/style.css: https://github.com/openedx/edx-platform/blob/master/xmodule/assets/library_source_block/style.css | ||
.. _webpack.common.config.js: https://github.com/openedx/edx-platform/blob/master/webpack.common.config.js |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.