Bootswatch theme-preset breaks Moodle 3.2.1+

Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -
Number of replies: 19

Was using Moodle 3.2 with Boost theme.
Installed the "united" theme-preset from Bootswatch to the Boost theme.
No problem, everything looked good.

I then upgraded Moodle to 3.2.1+ and lost all CSS. Just text on white pages.

Restored back to Moodle 3.2
Set the "theme-preset" attribute for the Boost theme back to default.scss
Upgraded to Moodle 3.2.1+
No problem.

I then changed the "theme-preset" attribute for the Boost theme to "united",
and lost the CSS again.

Average of ratings: -
In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Sorry, I forgot to note the Build number for M3.2.1+

It was the latest one as of this post.

In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Has anyone tried using a Boost theme preset from Bootswatch in Moodle 3.2.1+ as discussed here?

In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by pst tomowo George -

hi,


i am a newbie...

had similar experience. 

wanted the beauty of the bootswatch theme and all that came with moodle 3.2+ however i got a white page with text....

i quickly removed the copied css from the bootswatch and it returned back to my original 


i really want to have some beautiful background for our site.


i am a newbie... 

pls help..


our site;  http://coaching.air.church


thanks

In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Richard Jones -
Picture of Plugin developers Picture of Testers
Hi Mark


Yes, I have the same issue with the latest Moodle.  Have you filed a bug report yet?

Cheers

Richard

In reply to Richard Jones

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Richard Jones -
Picture of Plugin developers Picture of Testers

I just loaded up a brand new install 3.2.1+ version  2016120501.04 build 20170202 and then added the preset-morecandy.scss from the Moodle site and everything worked fine.

So the problem is most likely the preset you/we are using.  Or possibly there is a fix already.

You only need a small error to stuff up a preset file!

Richard

In reply to Richard Jones

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Hi Richard -

I have tried twice to report the problem at the Tracker, but keep this reply (bold is mine):

Dear Moodler, before creating a new issue you need to demonstrate that you have searched among the existing issues to see if it's already been filed. Please find a similar issue from among the open issues and either start watching it or vote for it.

How to demonstrate that I have indeed searched?
There are some entries in the Tracker related to Bootswatch, but none about this specific issue, or none that I can find.

Since I cannot add a bug report, I added a comment to MDL-57313 which is the closest related issue I could find.


In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello all,

Came across this post and replies by accident.  I'm good with themes, really good and would have replied sooner if had been in the themes forum.

Ok, looking at the problem I think that the information on https://moodle.net/mod/data/view.php?id=28 is misleading.  The Bootswatch site main area is for Bootstrap V3 themes of which there are a few contributed ones.  Clean (child of Bootstrapbase) and others is Bootstrap V2 based.  However Boost is Bootstrap V4 (in development) based - therefore try the presets currently under development for that version of Bootstrap instead from the Bootswatch GitHub: https://github.com/thomaspark/bootswatch/tree/gh-pages/4-alpha - so for 'United' try the SCSS files in: https://github.com/thomaspark/bootswatch/tree/gh-pages/4-alpha/united.

I believe this is a separate issue as searched on the tracker with "text ~ "bootswatch" AND resolution = Unresolved order by priority DESC,updated DESC" and did not find anything specific.  MDL-43788 comes close.  So I think this is a link issue and raised: MDLSITE-4952.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Hi Gareth -

I have done the following:

  1. downloaded _bootswarch.scss and _variables.scss for the united preset from the bootswatch repo at github as you suggested.
    bootswatch/4-alpha/united

  2. put the the two .scss files in - /var/www/moodle/theme/boost/cli

  3. ran
    >sudo php import-bootswatch.php

  4. Got the following error
    == Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4. ==
    PHP Notice:  Undefined variable: newstring in /var/www/moodle/theme/boost/cli/import-bootswatch.php on line 89
    PHP Notice:  Undefined variable: newstring in /var/www/moodle/theme/boost/cli/import-bootswatch.php on line 89
    PHP Notice:  Undefined variable: newstring in /var/www/moodle/theme/boost/cli/import-bootswatch.php on line 89
    PHP Notice:  Undefined variable: newstring in /var/www/moodle/theme/boost/cli/import-bootswatch.php on line 89
    PHP Notice:  Undefined variable: newstring in /var/www/moodle/theme/boost/cli/import-bootswatch.php on line 89

    (BTW, I did not get any errors when using the .scss files from the bootswatch website.)

  5. The file preset.scss was created.
    For kicks I tried to use the newly created preset.scss file, but got the same result as when using the preset from the bootswatch website, namely, no CSS (text on white pages).
In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, so the script does more than I thought it would.  So therefore I've closed the MDLSITE issue and will have a look at both version imports.

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok, the V3 Bootswatch presets are failing with this stack trace:

[05-Feb-2017 13:08:11 Europe/London] PHP Notice:  Array to string conversion in F:\moodledev\moodle32\lib\scssphp\Compiler.php on line 2727
[05-Feb-2017 13:08:11 Europe/London] Default exception handler: Exception - unknown value type: Array: line: 944 Debug: 
Error code: generalexceptionmessage
* line 3418 of \lib\scssphp\Compiler.php: Leafo\ScssPhp\Exception\CompilerException thrown
* line 2727 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->throwError()
* line 2756 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->compileValue()
* line 115 of \lib\classes\scss.php: call to Leafo\ScssPhp\Compiler->compileStringContent()
* line 1274 of \lib\scssphp\Compiler.php: call to core_scss->compileChild()
* line 295 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->compileChildrenNoReturn()
* line 194 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->compileRoot()
* line 98 of \lib\classes\scss.php: call to Leafo\ScssPhp\Compiler->compile()
* line 1216 of \lib\outputlib.php: call to core_scss->to_css()
* line 884 of \lib\outputlib.php: call to theme_config->get_css_content_from_scss()
* line 171 of \theme\styles.php: call to theme_config->get_css_content()

So a bug to report.

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Patching the cli script with:

function str_replace_one($needle, $replace, $haystack) {
    $pos = strpos($haystack, $needle);
    if ($pos !== false) {
        $newstring = substr_replace($haystack, $replace, $pos, strlen($needle));
        return $newstring;
    }
    return $haystack;
}

and trying the V4 version gives:

[05-Feb-2017 13:16:09 Europe/London] Default exception handler: Exception - Undefined variable $btn-default-color: line: 398 Debug: 
Error code: generalexceptionmessage
* line 3418 of \lib\scssphp\Compiler.php: Leafo\ScssPhp\Exception\CompilerException thrown
* line 3088 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->throwError()
* line 2091 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->get()
* line 1575 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->reduce()
* line 126 of \lib\classes\scss.php: call to Leafo\ScssPhp\Compiler->compileChild()
* line 1274 of \lib\scssphp\Compiler.php: call to core_scss->compileChild()
* line 295 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->compileChildrenNoReturn()
* line 194 of \lib\scssphp\Compiler.php: call to Leafo\ScssPhp\Compiler->compileRoot()
* line 98 of \lib\classes\scss.php: call to Leafo\ScssPhp\Compiler->compile()
* line 1216 of \lib\outputlib.php: call to core_scss->to_css()
* line 884 of \lib\outputlib.php: call to theme_config->get_css_content_from_scss()
* line 171 of \theme\styles.php: call to theme_config->get_css_content()

so need to think on how to fix the V3 conversion or just combine the V4 files into one without the script.

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Ok... found a solution:

So the issue is down to this line:

@import url($web-font-path);

with the 'url' bit.  I found: https://github.com/sass/libsass/issues/289 - which helped.  It might be that core code needs fixing.  Remove the line and the V3 preset will work.  I did the same on a self combined V4 version and it failed with no stack trace.

So, therefore the procedure is:

  1. Download V3 preset files.
  2. Run the import script.
  3. Edit the output to remove '@import url' statements.
So this means that the Moodle core SASS PHP compiler does not support '@import url' and therefore needs to do so.
In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Additional as '@import url' is a CSS rather than a SASS thing I thought as LESS has ~"" for 'pass-through' then why not for SASS?  But.... a look at http://stackoverflow.com/questions/25136523/ignore-parts-of-sass-file-for-parsing says 'no' and talks about 'unquote'.  So tried that in many forms and places (including Boost lib.php callbacks), but no, so currently the only way I've found is to edit the Mustache templates, then within the 'head' section do something like:

<head>
    <title>{{{ output.page_title }}}</title>
    <link rel="shortcut icon" href="{{{ output.favicon }}}" />
    <style>@import url('//fonts.googleapis.com/css?family=Ubuntu:400,700');</style>
    {{{ output.standard_head_html }}}
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

where you can see a 'style' tag with the import before any other CSS as per the CSS rules: https://developer.mozilla.org/en/docs/Web/CSS/@import.

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Definitely a bug, so: MDL-57875 raised.

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

*Many* thanks for your help with this Gareth.

I have voted for the issue at the Tracker. smile

Hoping they can sort this quickly; I am not keen on the default color scheme in Boost.

- mark

In reply to Gareth J Barnard

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Thank you Gareth. I appreciate that.
You mentioned that the bug report has been moved to the "themes forum".

When I click on the link you sent,
https://moodle.org/mod/forum/discuss.php?d=346241
I noticed the breadcrumb trail says it is in the "Moodle in English > Other components" section of the forum.
I cannot find "Other components" when navigating the forums.

- mark

Attachment Screen Shot 2017-02-07 at 8.32.03 AM.png
In reply to Mark Hayes

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Richard Oelmann -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

See also the existing discussion at https://moodle.org/mod/forum/discuss.php?d=345659

The issue with the @import url was identified there too - although Gareth has done far more work in identifying and possibly addressing that issue. The result from that discussion (as yet) is that the boostswatch presets that I had previously converted from bootswatch have all had the offending line commented out and do work - although this does mean that they don't apply there fonts correctly. That can be addressed with Gareth's work around of adding the font api call in <head> although I'm looking for a better solution (which would ideally be the bug itself getting fixed).

The already compiled-for-moodle boostswatch presets are available either as part of the Waxed theme download or from my github repository


Hope that helps

Richard

In reply to Richard Oelmann

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Richard Oelmann -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

In the github development version of Waxed, I've added these @imports url(some font reference) to a separate .css file. Not yet on the database as i have a few more things to do.

That means they all get called (I've avoided duplicates between bootswatch presets) but it means the fonts work for each preset - It avoids having to mess about with the template files and keeps it separate from the layout files/templates.

Loading all the font css files for the presets even though only one will be in use isn't ideal, but I'm happy with it as a workaround for this issue for Waxed, which has all the bootswatches preloaded . If you are using Boost and adding just one preset, then going with Gareth's solution of adding the @import line to <head> in the layout is probably a better idea than having to create a new separate css file for one line smile

In reply to Richard Oelmann

Re: Bootswatch theme-preset breaks Moodle 3.2.1+

by Mark Hayes -

Many thanks for that Richard.

Will have a look at Waxed on my test machine.

- mark