-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theming using SCSS variables #3531
Conversation
@juliushaertl, thanks for your PR! By analyzing the history of the files in this pull request, we identified @skjnldsv, @rullzer and @ChristophWurst to be potential reviewers. |
'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' . | ||
'background-size: contain;' . | ||
'}' . "\n" . | ||
'#header .logo, ' . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we pass the logo as a variable too? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be possible. I'll have a look. :)
lib/private/Template/SCSSCacher.php
Outdated
$injectedVariables = $this->getInjectedVariables(); | ||
if($injectedVariables !== '' && $this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) { | ||
$this->resetCache(); | ||
$this->config->setAppValue('core', 'scss.variables', md5($injectedVariables)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather like to use ICache here but since there is no caching enabled as a default, we would be generating the css code on every request. It's a little missuse of the appConfig but since it is loaded into memory on every request, there is no overhead when requesting existing files. We only have one database update per changing scss variables. Feedback for that would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't cache enable my default no matter we have redis/memcache enabled?
Isn't there a filecaching fallback for this purpose only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I 've been using the ICache function on my fbsync extension since a year and I remember it was working before I enabled redis iirc :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least it was not on my simple dev setup.
https://github.com/nextcloud/server/blob/master/lib/private/Server.php#L393-L406 looks like it was because PHPUNIT was enabled. Not sure if it is ok to regenerate everytime in dev setups, it is so slow then :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/nextcloud/server/blob/master/lib/private/Server.php#L393-L406 looks like it was because PHPUNIT was enabled. Not sure if it is ok to regenerate everytime in dev setups, it is so slow then :(
The define there should only trigger if PHPUnit is actually running (e.g. on test execution)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 🚀
Some nitpicks in the other comments here, mainly about unit tests and questions :)
apps/theming/lib/ThemingDefaults.php
Outdated
@@ -150,6 +154,29 @@ public function getBackground() { | |||
} | |||
} | |||
|
|||
|
|||
public function getScssVariables() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs PHPDoc and a small unit test :)
lib/private/Template/SCSSCacher.php
Outdated
*/ | ||
public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $urlGenerator, SystemConfig $systemConfig) { | ||
public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $urlGenerator, IConfig $config, \OC_Defaults $defaults) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer adding each of them on a newline to keep the code easier to read without having to scroll :)
lib/private/Template/SCSSCacher.php
Outdated
* @param ISimpleFolder $folder | ||
* @return bool | ||
*/ | ||
private function variablesChanged($fileNameCSS, ISimpleFolder $folder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests please :)
lib/private/Template/SCSSCacher.php
Outdated
try { | ||
$variablesFile = \OC::$SERVERROOT . '/core/css/variables.scss'; | ||
$cachedFile = $folder->getFile($fileNameCSS); | ||
if ($cachedFile->getMTime() < filemtime($variablesFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this block is because of updates in dev environments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Otherwise changing anything in variables.scss will not trigger regenerating the css files.
lib/private/Template/SCSSCacher.php
Outdated
* Reset scss cache by deleting all generated css files | ||
* We need to regenerate all files when variables change | ||
*/ | ||
public function resetCache() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made those public so i can add unit test for those easily later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also test private methods. We have a helper for that, check \Test\TestCase::invokePrivate
and it's usages :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can also cover them just with the existing public methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice 👍 I wasn't aware of that.
lib/private/Template/SCSSCacher.php
Outdated
/** | ||
* @return string SCSS code for variables from OC_Defaults | ||
*/ | ||
public function getInjectedVariables() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be public?
4afee67
to
4d0386a
Compare
Time for review. |
@nextcloud/theming |
apps/theming/lib/ThemingDefaults.php
Outdated
@@ -58,27 +60,30 @@ class ThemingDefaults extends \OC_Defaults { | |||
* @param IL10N $l | |||
* @param IURLGenerator $urlGenerator | |||
* @param \OC_Defaults $defaults | |||
* @param IRootFolder $rootFolder | |||
* @param IRootFolder $appData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class needs changing as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logo is disappearing with this. Let me try to find the responsible code :)
GET http://10.211.55.7/stable9//stable9/core/img/logo.svg?v=1 404 (Not Found)
The one /stable9/ seems too much.
Codecov Report
@@ Coverage Diff @@
## master #3531 +/- ##
============================================
- Coverage 53.96% 2.62% -51.34%
- Complexity 21679 21694 +15
============================================
Files 1272 1272
Lines 75789 75096 -693
============================================
- Hits 40898 1970 -38928
- Misses 34891 73126 +38235
|
apps/theming/lib/ThemingDefaults.php
Outdated
]; | ||
|
||
$variables['image-logo'] = "'../../".$this->getLogo()."'"; | ||
$variables['image-login-background'] = "'../../".$this->getBackground()."'"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* override styles for login screen in guest.css */
/* line 42, /media/psf/stable9/apps/theming/css/theming.scss */
#header .logo, #header .logo-icon {
background-size: contain;
background-image: url(../../..//stable9/core/img/logo.svg?v=1);
}
Generated URL is wrong :)
Failing tests (weirdly there is now a
|
bd61522
to
2b0ac50
Compare
Needs a rebase |
1039404
to
72fc360
Compare
Squashed and rebased, but I haven't tested it. |
Just in case I messed something up I also have a local backup branch available ;) |
@MorrisJobke Works as expected. I've just added another commit that ensures that the css files will be reloaded if theming values are changed. Ready for review, I think. @nextcloud/theming |
apps/theming/lib/ThemingDefaults.php
Outdated
} | ||
|
||
return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; | ||
return $this->urlGenerator->linkToRouteAbsolute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaks HTML mails, will have a look.
4e4cd89
to
abbd9fb
Compare
abbd9fb
to
6bf8fee
Compare
@nickvergessen Could you have a look? |
@@ -431,33 +454,61 @@ public function testGetLogoDefault() { | |||
->method('getFolder') | |||
->with('images') | |||
->willThrowException(new \Exception()); | |||
$expected = $this->urlGenerator->imagePath('core','logo.svg') . '?v=0'; | |||
$this->assertEquals($expected, $this->template->getLogo()); | |||
$this->assertEquals('/core/img/logo.svg?v=0', $this->template->getLogo()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this breaks because https://github.com/nextcloud/server/blob/master/apps/theming/lib/ThemingDefaults.php#L144 adds the \OC::$WEBROOT but https://github.com/nextcloud/server/blob/master/apps/theming/lib/ThemingDefaults.php#L169 does not.
Which feels very wrong...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both should add the webroot...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted the test
Signed-off-by: Julius Haertl <[email protected]> Add Scss variables to example theme and theming app Signed-off-by: Julius Haertl <[email protected]> Use SCSSCacher to build theming css Signed-off-by: Julius Härtl <[email protected]> Update theming.scss Signed-off-by: Julius Härtl <[email protected]> Code cleanup Signed-off-by: Julius Härtl <[email protected]> Fix tests Signed-off-by: Julius Härtl <[email protected]> Inject SCSSCacher for easier testing Signed-off-by: Julius Härtl <[email protected]> Fix typehint Signed-off-by: Lukas Reschke <[email protected]> Generate absolute URLs Signed-off-by: Lukas Reschke <[email protected]> Fix tests to always use absolute urls for theming images Signed-off-by: Julius Härtl <[email protected]> MailheaderColor -> ColorPrimary Signed-off-by: Roeland Jago Douma <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
Signed-off-by: Julius Härtl <[email protected]>
They are used way to often for such a change Signed-off-by: Joas Schilling <[email protected]>
6bf8fee
to
bedd500
Compare
|
||
public function setUp() { | ||
parent::setUp(); | ||
$this->config = $this->getMockBuilder(IConfig::class)->getMock(); | ||
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); | ||
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); | ||
$this->urlGenerator = \OC::$server->query(IURLGenerator::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this replaced anyway... I will revert this as well
Signed-off-by: Joas Schilling <[email protected]>
@juliushaertl @nickvergessen @rullzer @skjnldsv is there anything specifically blocking it, or anything to change/add? Seems to work well. :) |
Failing test is due to the JS unit problem - see #4494 for a fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
Requires #3256
Custom themes as well as the theming app will get a lot simpler with #3256. We can just overwrite the existing SCSS variables and can drop most of the string concatenated CSS code inside of the ThemingController.
There will be also much less maintenance work for the theming app in order to keep up with any CSS code changes.
@skjnldsv @nextcloud/theming @nextcloud/designers
Custom themes
With this you can apply a different color scheme to custom themes like this:
ToDo