Skip to content

saleem-latif/WL-299: SCSS Overrides for Comprehensive Theming - #11476

Closed
saleem-latif wants to merge 1 commit into
masterfrom
saleem-latif/WL-299
Closed

saleem-latif/WL-299: SCSS Overrides for Comprehensive Theming#11476
saleem-latif wants to merge 1 commit into
masterfrom
saleem-latif/WL-299

Conversation

@saleem-latif

Copy link
Copy Markdown
Contributor

Hi @mattdrayer , @andy-armstrong, @mtyaka , @ziafazal , @benpatterson

Kindly review this PR and share your thoughts on these changes for WL-299.

Note:
Since, sass first looks at its current path to resolve @import so, We decided to move sass files, that comprehensive theme will be able to override, to partials directory. I have only moved base/_variables.scss to partials dir, if this change set looks good than also share your thoughts on what other sass files should be moved to partials dir.

Description of WL-299:
Currently the behavior of static files and templates overriding in comprehensive theming is that if we place a file named same as it is placed in lms it will override the lms static/template file.
We want to apply the same override pattern for sass files, see the discussion here and here for some insight.
Acceptance Criteria:

  1. If I place a file named base/_variables.scss inside edx-platform/themes/stanford/lms/static/sass/partials/ than it should override all the definitions from base/_variables.scss present in edx-platform/lms/static/sass/partials/

for more information regarding implementation details look at the comments on WL-299

@saleem-latif
saleem-latif force-pushed the saleem-latif/WL-299 branch 4 times, most recently from 1e69083 to 98dd913 Compare February 9, 2016 12:32
@mattdrayer

Copy link
Copy Markdown
Contributor

👍 LGTM @saleem-latif -- would be great if we could get one more thumb from the guys you've tagged -- @ziafazal is out for the rest of the week -- perhaps @mtyaka or @andy-armstrong can take a look?

@mattdrayer

Copy link
Copy Markdown
Contributor

@AlasdairSwan I'm not sure if you're doing much with the Sass pipeline, but if so maybe you could take a look as well

Comment thread pavelib/assets.py Outdated
if lms_sass.isdir():
lms_css.mkdir_p()
THEME_SASS_DIRECTORIES.append(lms_sass)
THEME_SASS_DIRECTORIES.append(("lms/static/sass", theme_dir / "lms" / "static" / "css"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can replace theme_dir / "lms" / "static" / "css" with lms_css, which is already defined a couple of lines above.

@mtyaka

mtyaka commented Feb 11, 2016

Copy link
Copy Markdown
Contributor

@saleem-latif Thanks for this, it looks great.

In addition to the comments I made inline:

  • Can we move the _variables.scss file one level up - from partials/base/_variables.scss to partials/_variables.scss? I imagine almost every theme will want to override this file, so it would be nicer if theme authors didn't have to create a base subfolder in their theme's partials folder just to override _variables.scss.
  • I would move all partial sass files to the partials directory. We allow theme authors to override any template and any static file, so I think it would make sense to let them override any sass file as well.

@saleem-latif

Copy link
Copy Markdown
Contributor Author

@mtyaka I tried moving _variables.scss to partials without base dir but then it would conflict with _variables.scss in cms/statis/sass dir. that is why I put it inside partials/base . but if we compile lms and cms's sass in separate commands then this problem will be resolved, as you mentioned in your previos comment, but I am not sure if how this approach will affect other things

Comment thread pavelib/assets.py Outdated
path("common/static/sass"),
(path("common/static/sass"), path("common/static/css"))
]
COMMON_SASS_LOOKUP_DIRECTORIES = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need more commentary in the code describing the function of the lookup directories.

@benpatterson

Copy link
Copy Markdown
Contributor

This PR needs tests.

@benpatterson

Copy link
Copy Markdown
Contributor

I'm a little concerned with how reliant this approach is to execution order. Can there be a way to do this that is more deterministic?

Comment thread pavelib/assets.py
css_dir=css_dir or sass_dir.parent / "css",
))
else:
sh("rm -rf {css_dir}/*.css".format(css_dir=css_dir))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to handle css_dir being falsey, like the dry_run case does?

@andy-armstrong

Copy link
Copy Markdown
Contributor

I agree with @benpatterson that this needs tests. Look at test_assets.py and extend it to demonstrate the behavior when a comprehensive theme is in play.

@andy-armstrong

Copy link
Copy Markdown
Contributor

I'm a little unsure about the idea of overriding partial files. It seems brittle to me, in that it is depending upon the naming conventions used to break up the SASS. It means that going forward, platform developers can't rename anything or change load order without the risk of breaking themes. It also means that the theme author has to know exactly how the platform author laid out all of their partials. If we do go down this path then we will have to be very careful to document what can be overridden by theme authors, and what therefore can't be changed by platform developers. We have essentially made the files on the disk into a contract that can't be changed.

There is also a risk of accidental overrides if a theme author has a new SASS partial, and then later the platform author happens to use the same filename. In this situation, the platform author won't know that they've broken the theme.

Having said this, it does seem very powerful too. It makes it much easier to change theme colors, fonts etc in a comprehensive way, without having to manually override every single CSS file with a theme version. If we are very explicit about the files that a theme author is allowed to override then maybe that's okay. One option worth considering is to have a named directory for the partials that are allowed to be overridden, to avoid any risk of accidental collisions.

@andy-armstrong

Copy link
Copy Markdown
Contributor

Thinking this through some more, I'm confused as to how this will work (this could well be because I'm not understanding things correctly). Say you have three installed themes: red, green and blue. Each one of these overrides variables.scss to define the brand colors to be appropriate to their theme. In order to support multi-tenancy, the result we want is that each theme directory has an lms-main-ltr.css (for example) that is compiled with its brand colors applied. When a request asks for the blue theme, the static file loader will look for the CSS file first in the blue theme directory and will pick it up if it is there. If it isn't, then it will instead load the default version of the CSS file.

If I'm understanding this PR correctly, what it does is put all three of these theme directories on the lookup path at once. This means that only the first listed theme will get to override variables.scss, and that this theme's values will be used to generate the default lms-main-ltr.css. This won't support multi-tenancy where we can dynamically switch themes per request.

Is my understanding correct here? To reiterate @benpatterson's point, it is crucial that we have tests that demonstrate that the desired use cases will work. Similarly, I recommend that we implement a URL parameter so that developers can easily switch themes, like we can with ?preview-lang=foo. If we can do ?preview-theme=red and then switch to ?preview-theme=blue that would allow us to make sure that the theming really is per request.

@mtyaka

mtyaka commented Feb 12, 2016

Copy link
Copy Markdown
Contributor

@andy-armstrong This PR only deals with SASS compilation, not with django static asset lookup path. It currently assumes a single theme, but it wouldn't be hard to extend this to support multiple themes; sass compilation would just have to be run separately for each installed theme.

Multi-tenancy and multi-theme support are being worked on in a separate PR: https://github.com/edx/edx-platform/pull/11480

@mtyaka

mtyaka commented Feb 12, 2016

Copy link
Copy Markdown
Contributor

@andy-armstrong I understand your concerns about themes being brittle if we allow overriding arbitrary sass partials. The same could be said of templates and static files (images, etc), though. We already support overriding arbitrary django/mako templates and static files from a theme, but that doesn't mean we can't change or rename any template in edx-platform. As a theme author, I understand overriding templates is brittle, but I still do it sometimes when there's no better solution, and I am grateful I can do that in a custom theme instead of having to change templates directly in a fork of edx-platform.

Themes almost always have to be adapted for new major releases of edx-platform due to changes in HTML structures and CSS rules, so theme authors expect to have to do some work when upgrading.

Still, I don't think overriding partials other than a few selected and documented ones (ie. _variables.scss) should be considered good practice, but I would really like to have the ability to do that.

@andy-armstrong

Copy link
Copy Markdown
Contributor

@mtyaka Thanks for the well thought out replies.

It is good to hear that you don't think it would be hard to add support for multiple themes. To my mind, I wouldn't want to merge this without it, because we know that's what we need. I think the key is that the theme's SASS overrides should only apply to the theme's own CSS files, which as you suggest seems that there should be a separate compilation step performed per theme.

Regarding overrides, I think we're in agreement. Overriding most partials will be risky and error prone, so we should just make it clear which ones make sense, i.e. _variables.scss and a handful of others.

I'm on vacation all next week, so if possible it would be ideal to hold off merging until I get back. If you need this sooner then I recommend getting @AlasdairSwan's opinion. Thanks.

@saleem-latif
saleem-latif force-pushed the saleem-latif/WL-299 branch 4 times, most recently from 25f0eb5 to 3c9a97b Compare February 15, 2016 13:47
@mattdrayer

Copy link
Copy Markdown
Contributor

@AlasdairSwan, it would be great if you could take a look at this PR -- thanks!

@saleem-latif
saleem-latif force-pushed the saleem-latif/WL-299 branch 5 times, most recently from 172ce86 to 430bdf1 Compare February 16, 2016 14:51
@mattdrayer

Copy link
Copy Markdown
Contributor

jenkins run python

@mattdrayer

Copy link
Copy Markdown
Contributor

jenkins run lettuce

@benpatterson

Copy link
Copy Markdown
Contributor

I'm about half-way through a pass on this. However, this still seems fairly dependent on the order of operations. Is there a smarter way to do it?

@saleem-latif
saleem-latif force-pushed the saleem-latif/WL-299 branch 3 times, most recently from 2aba17d to c5767c5 Compare February 17, 2016 07:38
@mattdrayer

Copy link
Copy Markdown
Contributor

@benpatterson, it appears that @saleem-latif has updated this PR with a new commit -- can you take another look and let us know what else you'd like to see?

@benpatterson

Copy link
Copy Markdown
Contributor

@saleem-latif did you make additional changes? It looks like a squash and/or rebase to me...

@saleem-latif

Copy link
Copy Markdown
Contributor Author

@benpatterson yes I made the changes that you suggested in the feedback.

@saleem-latif

Copy link
Copy Markdown
Contributor Author

jenkins run lettuce

@saleem-latif

Copy link
Copy Markdown
Contributor Author

@benpatterson I have divided test cases into multiple tests, kindly take a look.

@mattdrayer mattdrayer changed the title (WIP) - WL-299: Updates sass compilation path so that scss in themes overrides lms/cms's sass files saleem-latif/WL-299: SCSS Overrides for Comprehensive Theming Feb 23, 2016
"""
Disable comprehensive theme and clear changes made for comprehensive themes.
"""
patch("pavelib.assets.Env.env_tokens", {'COMPREHENSIVE_THEME_DIR': ""})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line necessary when the env_tokens is only updated within a with clause that should clean up?

@andy-armstrong

Copy link
Copy Markdown
Contributor

@saleem-latif Thanks for addressing all of my feedback. The code looks very clear now, and the tests are excellent.

Unfortunately I'm still uncomfortable with the approach, i.e. that the configured theme changes the way that the non-themed CSS files are generated. This seems like it will be confusing to folks who try to change their theme but don't think to regenerate their CSS. It will be important to document this clearly in the comprehensive theming documentation. My bigger concern is that this approach doesn't work for multi-tenancy, and we know that's where we want to go. I looked at the multi-tenancy PR (https://github.com/edx/edx-platform/pull/11480) but that doesn't seem to address SASS compilation as yet.

I don't see that there's enough benefit to the theme developer with this change, when they will have to change everything they do when we support multi-tenancy. Is the thinking that this approach will continue to work for folks who don't need multi-tenancy even when we add full support for it for ourselves? How are you imagining that this will work? I'd like to see a clear architectural design for multi-tenant theming and understand how this work fits into it before approving this PR.

@mattdrayer can we discuss this the next time you're in the office so that we can both be on the same page. FYI @efagin @nedbat.

@caesar2164

Copy link
Copy Markdown
Contributor

@andy-armstrong & devs: wouldn't it be better to allow overriding of just the base colors (i.e. $black, $red, $blue, etc...) and then let all the other vars just automagically generated themselves?

@caesar2164

Copy link
Copy Markdown
Contributor

@mattdrayer & @saleem-latif, so you guys get a ping about ^

@mattdrayer

Copy link
Copy Markdown
Contributor

@andy-armstrong PR #11480 is an older attempt at multi-tenant theming that has since been closed -- instead please reference #11613

@saleem-latif

Copy link
Copy Markdown
Contributor Author

Closing this PR as the development of the feature has shifted to #11613

@saleem-latif
saleem-latif deleted the saleem-latif/WL-299 branch July 27, 2016 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants