MDL-55563 theme_noname: Added a bootswatch importer and 3 default bootswatches

Part of MDL-55071
This commit is contained in:
Damyon Wiese
2016-09-23 10:53:30 +01:00
committed by Dan Poltawski
parent 75d6a7d318
commit ef18a21f93
8 changed files with 4232 additions and 1 deletions
+266
View File
@@ -0,0 +1,266 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script fixed incorrectly deleted users.
*
* @package core
* @subpackage cli
* @copyright 2013 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
require(__DIR__.'/../../../config.php');
require_once($CFG->libdir.'/clilib.php');
// Now get cli options.
list($options, $unrecognized) = cli_get_params(array('help'=>false),
array('h'=>'help', 'v'=>'variables', 'b'=>'bootswatch', 'p'=>'preset'));
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
if (!isset($options['variables'])) {
$options['variables'] = '_variables.scss';
}
if (!isset($options['bootswatch'])) {
$options['bootswatch'] = '_bootswatch.scss';
}
if (!isset($options['preset'])) {
$options['preset'] = 'preset.scss';
}
if ($options['help']) {
$help =
"Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4.
This scripts takes the scss files from a Bootstrap 3 Bootswatch and produces a Moodle compatible preset file.
Options:
-h, --help Print out this help
-v, --variables=<variables file>
-b, --bootswatch=<bootswatch file>
-p, --preset=<preset file>
Example:
\$import-bootswatch.php -v=_variables.scss -b=_bootswatch.scss -p=preset-paper.scss
";
echo $help;
die;
}
cli_heading('Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4.');
$variablesfile = $options['variables'];
$bootswatchfile = $options['bootswatch'];
$presetfile = $options['preset'];
$sourcevariables = @file_get_contents($variablesfile);
if (!$sourcevariables) {
die('Could not read variables file: ' . $variablesfile . "\n");
}
$sourcebootswatch = @file_get_contents($bootswatchfile);
if (!$sourcebootswatch) {
die('Could not read bootswatch file: ' . $bootswatchfile . "\n");
}
function str_replace_one($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos !== false) {
$newstring = substr_replace($haystack, $replace, $pos, strlen($needle));
}
return $newstring;
}
$out = @fopen($presetfile, "w");
if (!$out) {
die('Could not open preset file for writing: ' . $presetfile . "\n");
}
// Write the license (MIT).
$license = <<<EOD
//
// The MIT License (MIT)
//
// Copyright (c) 2013 Thomas Park
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
EOD;
fwrite($out, $license);
$workingvariables = $sourcevariables;
// Now start tweaking the variables strings.
// Insert a lightest grey colour.
$newrule = '$gray-lightest: lighten($gray-lighter, 13.5%);';
$nextline = '$brand-primary';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Set body-color to text-color.
$newrule = '$body-color: $text-color;';
$nextline = '//** Global textual link color.';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Add a font-size-root the same as font-size-base;
$newrule = '$font-size-root: $font-size-base;';
$nextline = '$font-size-large';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Replace all 'large' with 'lg'.
$workingvariables = str_replace('large', 'lg', $workingvariables);
// Replace all 'small' with 'sm'.
$workingvariables = str_replace('small', 'sm', $workingvariables);
// Replace all 'vertical' with 'y'.
$workingvariables = str_replace('vertical', 'y', $workingvariables);
// Replace all 'horizontal' with 'x'.
$workingvariables = str_replace('horizontal', 'x', $workingvariables);
// Replace all 'border-radius-base' with 'border-radius'.
$workingvariables = str_replace('border-radius-base', 'border-radius', $workingvariables);
// Replace all 'condensed-cell' with 'sm-cell'.
$workingvariables = str_replace('condensed-cell', 'sm-cell', $workingvariables);
// Add styles for btn-secondary.
$newrule = '$btn-secondary-color: $btn-default-color;
$btn-secondary-bg: $btn-default-bg;
$btn-secondary-border: $btn-default-border;
';
$nextline = '$btn-primary-color';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Add a input-border rule matching input-border-color.
$newrule = '$input-border-color: $input-border;';
$nextline = '$input-border-radius:';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Replace all 'input-height-base:' with 'input-height:'.
$workingvariables = str_replace('input-height-base:', 'input-height:', $workingvariables);
// Replace all '-default-' with '-light-'.
$workingvariables = str_replace('navbar-default-', 'navbar-light-', $workingvariables);
// Replace all '-inverse-' with '-dark-'.
$workingvariables = str_replace('navbar-inverse-', 'navbar-dark-', $workingvariables);
// Add a pagination-border-color rule matching pagination-border.
$newrule = '$pagination-border-color: $pagination-border;';
$nextline = '$pagination-hover-color';
$workingvariables = str_replace_one($nextline, "$newrule\n\n$nextline", $workingvariables);
// Replace all 'label-' with 'tag-'.
$workingvariables = str_replace('label-', 'tag-', $workingvariables);
// Replace all 'panel-' with 'card-'.
$workingvariables = str_replace('panel-', 'card-', $workingvariables);
fwrite($out, $workingvariables);
fwrite($out, '
@import "moodle";
');
// Now replacements on the bootswatch.
$workingbootswatch = $sourcebootswatch;
$mixins = <<<EOD
@mixin placeholder(\$text) {
placeholder: \$text;
}
@mixin box-shadow(\$text) {
box-shadow: \$text;
}
@mixin transform(\$transforms) {
transform: \$transforms;
}
@mixin rotate (\$deg) {
@include transform(rotate(#{\$deg}deg));
}
@mixin scale(\$scale) {
@include transform(scale(\$scale));
}
@mixin translate (\$x, \$y) {
@include transform(translate(\$x, \$y));
}
@mixin skew (\$x, \$y) {
@include transform(skew(#{\$x}deg, #{\$y}deg));
}
@mixin transform-origin (\$origin) {
transform-origin: \$origin;
}
EOD;
// Prepend some mixins.
$workingbootswatch = $mixins . $workingbootswatch;
// Replace all 'large' with 'lg'.
$workingbootswatch = str_replace('large', 'lg', $workingbootswatch);
// Replace all 'small' with 'sm'.
$workingbootswatch = str_replace('small', 'sm', $workingbootswatch);
// Replace all 'vertical' with 'y'.
$workingbootswatch = str_replace('vertical', 'y', $workingbootswatch);
// Replace all 'horizontal' with 'x'.
$workingbootswatch = str_replace('horizontal', 'x', $workingbootswatch);
// Replace all 'border-radius-base' with 'border-radius'.
$workingbootswatch = str_replace('border-radius-base', 'border-radius', $workingbootswatch);
// Replace all 'condensed-cell' with 'sm-cell'.
$workingbootswatch = str_replace('condensed-cell', 'sm-cell', $workingbootswatch);
// Replace all 'input-height-base:' with 'input-height:'.
$workingbootswatch = str_replace('input-height-base:', 'input-height:', $workingbootswatch);
// Replace all '-default-' with '-light-'.
$workingbootswatch = str_replace('navbar-default-', 'navbar-light-', $workingbootswatch);
// Replace all '-inverse-' with '-dark-'.
$workingbootswatch = str_replace('navbar-inverse-', 'navbar-dark-', $workingbootswatch);
// Replace all 'label-' with 'tag-'.
$workingbootswatch = str_replace('label-', 'tag-', $workingbootswatch);
// Replace all 'panel-' with 'card-'.
$workingbootswatch = str_replace('panel-', 'card-', $workingbootswatch);
fwrite($out, $workingbootswatch);
fclose($out);
+5
View File
@@ -0,0 +1,5 @@
This CLI script can be used to convert a bootswatch file from https://bootswatch.com/ to a Moodle preset.
To use it - download the _variables.scss and the _bootswatch.scss files for the chosen bootswatch into the current
folder and run "php import-bootswatch.php". This will generate a new file "preset.scss" which can be put
into the scss file as a Moodle preset.
+3
View File
@@ -36,6 +36,9 @@ $string['pluginname'] = 'NONAME';
$string['preset'] = 'Theme preset';
$string['preset_desc'] = 'Pick a preset to broadly change the look of the theme.';
$string['presetdefault'] = 'Default';
$string['presetflatly'] = 'Flatly';
$string['presetpaper'] = 'Paper';
$string['presetreadable'] = 'Readable';
$string['rawscss'] = 'Raw SCSS';
$string['rawscss_desc'] = 'Use this field to provide SCSS code which will be injected at the end of the the stylesheet.';
$string['region-side-post'] = 'Right';
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -32,7 +32,10 @@ if ($ADMIN->fulltree) {
$description = get_string('preset_desc', 'theme_noname');
$choices = [
// A file named 'preset-' . key . '.scss' is expected.
'default' => get_string('presetdefault', 'theme_noname')
'default' => get_string('presetdefault', 'theme_noname'),
'flatly' => get_string('presetflatly', 'theme_noname'),
'paper' => get_string('presetpaper', 'theme_noname'),
'readable' => get_string('presetreadable', 'theme_noname')
];
$default = 'default';
$setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
+14
View File
@@ -98,4 +98,18 @@
<version>1.3.3</version>
<licenseversion></licenseversion>
</library>
<library>
<location>scss/preset-flat.scss</location>
<name>Flatly Bootswatch</name>
<license>(MIT)</license>
<version>3.3.7</version>
<licenseversion></licenseversion>
</library>
<library>
<location>scss/preset-paper.scss</location>
<name>Paper Bootswatch</name>
<license>(MIT)</license>
<version>3.3.7</version>
<licenseversion></licenseversion>
</library>
</libraries>