Skip to content

Commit

Permalink
#155 Add support of SCSS in flavor raw scss
Browse files Browse the repository at this point in the history
  • Loading branch information
mwehr committed Jul 18, 2023
1 parent 0701f6c commit 18f4675
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
6 changes: 1 addition & 5 deletions classes/form/flavour_edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,7 @@ public function definition() {
$mform->addRule('bootstrapcolordanger', get_string('validateerror', 'admin'), 'theme_boost_union_colourpicker_rule');

// Add custom css as textarea element.
// Note: In the current state of implementation, this setting only allows the usage of custom CSS, not SCSS.
// It will be appended to the stack of CSS code which is shipped to the browser.
// There is a follow-up issue on Github to add SCSS support.
// When this is realized, the widget's title string should be changed to 'theme_boost/rawscss'.
$mform->addElement('textarea', 'look_rawscss', get_string('flavourscustomcss', 'theme_boost_union'), array('rows' => 15));
$mform->addElement('textarea', 'look_rawscss', get_string('rawscss', 'theme_boost'), array('rows' => 15));
$mform->setType('title', PARAM_TEXT);
$mform->addHelpButton('look_rawscss', 'flavourscustomcss', 'theme_boost_union');

Expand Down
27 changes: 13 additions & 14 deletions flavours/flavourslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,30 +317,29 @@ function theme_boost_union_flavour_exists_for_cohort($cohortid) {
/**
* Helper function do get a config key from flavour item.
*
* @param $flavourid
* @param $configkey
* @param string $flavourid
* @param string $configkey
*
* @return false
* @return string/bool
*/
function theme_boost_union_get_flavour_config_item_for_id($flavourid, $configkey) {
function theme_boost_union_get_flavour_config_item_for_id(string $flavourid, string $configkey) {
global $DB;

$cache = cache::make('theme_boost_union', 'flavours');

$flavouridkey = 'flavour_' . $flavourid;
// Get the cached flavour for the current user flavour id.
$flavour = $cache->get($flavouridkey);
// Get the cached flavour config for the current user flavour id.
$flavourconfig = $cache->get($flavouridkey);

// If we got a cached flavour.
if ($flavour == false) {
$flavour = $DB->get_record('theme_boost_union_flavours', ['id' => $flavourid]);
// If we got a cached flavour config.
if ($flavourconfig == false) {
$flavourconfig = $DB->get_record('theme_boost_union_flavours', ['id' => $flavourid]);
$cache->set($flavouridkey, $flavourconfig);
}

if ($flavour !== false ) {
$cache->set($flavouridkey, $flavour);
if (isset($flavour->{$configkey})) { // ...isset returns true only if property exits and value != null;.
return $flavour->{$configkey};
}
if (isset($flavourconfig->{$configkey})) { // ...isset returns true only if property exits and value != null;.
return $flavourconfig->{$configkey};
}

return false;
}
4 changes: 2 additions & 2 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@
$string['flavoursbrandcolour'] = 'Brand colour ';
$string['flavoursbrandcolour_help'] = 'With this setting, the flavour will override the brand colour which is configured in Boost Union\'s look settings.';
$string['flavourscreateflavour'] = 'Create flavour';
$string['flavourscustomcss'] = 'Custom CSS';
$string['flavourscustomcss_help'] = 'With this setting, you can write custom CSS for the flavour. It will be appended to the stack of CSS code which is shipped to the browser as soon as the flavour applies. Please note that in the current state of implementation, this setting only allows the usage of custom CSS, not SCSS.';
$string['flavourscustomcss'] = 'Custom SCSS';
$string['flavourscustomcss_help'] = 'With this setting, you can write custom SCSS for the flavour. It will be appended to the stack of CSS code which is shipped to the browser as soon as the flavour applies.';
$string['flavoursdelete'] = 'Delete';
$string['flavoursdeleteflavour'] = 'Delete flavour';
$string['flavoursdeleteconfirmation'] = 'Do you really want to delete the flavour <em>{$a}</em>?';
Expand Down
11 changes: 7 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ function theme_boost_union_get_pre_scss($theme) {
}
$scss .= '$blockregionoutsiderightwidth: '.$blockregionoutsiderightwidth.";\n";

// Prepend pre-scss.
if (!empty($theme->settings->scsspre)) {
$scss .= $theme->settings->scsspre;
if (isset($flavourid)) {
$rawscsspre = theme_boost_union_get_flavour_config_item_for_id($flavourid, 'look_rawscss');
// Append pre-scss.
if ($rawscsspre !== false) {
$scss .= "\n/** RAW-SCSS from theme_boost_union_get_pre_scss **/\n" . $rawscsspre;
}
}

// Since setting "precss" is originally from parent boost it is added in theme_boost_get_pre_scss.
return $scss;
}

Expand Down

0 comments on commit 18f4675

Please sign in to comment.