1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 02:04:35 +02:00

PR #189 – Additional updates to allow use of rock style without an admin.less file, plus add support for a core CSS version to detect when to force recompile of the /site/assets/admin.css file due to Uikit version upgrade or required core LESS/CSS changes.

Co-authored-by: BernhardBaumrock <office@baumrock.com>
This commit is contained in:
Ryan Cramer
2021-05-28 13:18:35 -04:00
parent 8d84f41620
commit 401fcb0781
4 changed files with 39 additions and 12 deletions

View File

@@ -20,7 +20,8 @@
* @property string $inputSize Size for input/select elements. One of "s" for small, "m" for medium (default), or "l" for large.
* @property bool|int $ukGrid When true, use uk-width classes for Inputfields (rather than CSS percentages).
* @property int $toggleBehavior (0=Standard, 1=Consistent)
* property string $configPhpHash Hash used internally to detect changes to $config->AdminThemeUikit settings.
* @property string $configPhpHash Hash used internally to detect changes to $config->AdminThemeUikit settings.
* @property int $cssVersion Current version number of core CSS/LESS files
*
* @method string getUikitCSS()
*
@@ -31,7 +32,7 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
public static function getModuleInfo() {
return array(
'title' => 'Uikit',
'version' => 32,
'version' => 33,
'summary' => 'Uikit v3 admin theme',
'autoload' => 'template=admin',
);
@@ -51,6 +52,14 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
*/
const upgrade = false;
/**
* Required CSS/LESS files version
*
* Increment on core less file changes that will also require a recompile of /site/assets/admin.css
*
*/
const requireCssVersion = 1;
/**
* Default logo image file (relative to this dir)
*
@@ -93,6 +102,7 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
$this->set('inputSize', 'm'); // m=medium (default), s=small, l=large
$this->set('ukGrid', false);
$this->set('configPhpHash', '');
$this->set('cssVersion', 0);
$this->setClasses(array(
'input' => 'uk-input',
'input-small' => 'uk-input uk-form-small',
@@ -1092,6 +1102,7 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
$settings = $config->AdminThemeUikit;
if(!is_array($settings)) $settings = array();
$settings['requireCssVersion'] = self::requireCssVersion;
if(self::upgrade) {
$settings['upgrade'] = true;

View File

@@ -15,6 +15,8 @@
*
* @property string $configPhpHash Hash used internally to detect changes to $config->AdminThemeUikit settings.
* @property string $configPhpName Name of property in $config that holds custom settings (default='AdminThemeUikit').
* @property int $requireCssVersion
* @property int $cssVersion
*
* Settings that may be specified in $config->AdminThemeUikit array:
*
@@ -30,11 +32,11 @@
class AdminThemeUikitCss extends WireData {
/**
* @var AdminTheme
* @var AdminTheme|AdminThemeUikit
*
*/
protected $adminTheme;
/**
* Construct
*
@@ -68,6 +70,8 @@ class AdminThemeUikitCss extends WireData {
'configPhpName' => $this->adminTheme->className(),
'configPhpHash' => $this->adminTheme->get('configPhpHash'),
'replacements' => array(),
'cssVersion' => (int) $this->adminTheme->get('cssVersion'),
'requireCssVersion' => 0,
);
}
@@ -101,12 +105,16 @@ class AdminThemeUikitCss extends WireData {
if($mtime > $lessTime) $lessTime = $mtime;
}
if(!count($lessFiles)) return $this->getDefaultCssFile($getPath);
if(!count($lessFiles) && ($this->style === '' || $this->style === $this->defaultStyle)) {
return $this->getDefaultCssFile($getPath);
}
$cssFile = $this->customFile($this->customCssFile, 'css');
if(!$cssFile) return $this->getDefaultCssFile();
if(!$cssFile) return $this->getDefaultCssFile($getPath);
$cssTime = is_file($cssFile) ? (int) filemtime($cssFile) : 0;
$recompile = $this->recompile || $lessTime > $cssTime || $this->configPhpSettingsChanged();
$recompile = $this->recompile || $lessTime > $cssTime || $this->cssVersion < $this->requireCssVersion;
if(!$recompile && $this->configPhpSettingsChanged()) $recompile = true;
}
if($recompile) try {
@@ -117,8 +125,14 @@ class AdminThemeUikitCss extends WireData {
$less->addFiles($lessFiles);
$options = array('replacements' => $this->replacements);
if(!$less->saveCss($cssFile, $options)) throw new WireException("Compile error: $cssFile");
$this->message(sprintf($this->_('Compiled: %s'), $cssFile), Notice::noGroup);
$messages = array(sprintf($this->_('Compiled: %s'), $cssFile));
$cssTime = filemtime($cssFile);
if($this->cssVersion < $this->requireCssVersion) {
$messages[] = "(core CSS v$this->cssVersion => v$this->requireCssVersion)";
$modules->saveConfig($this->adminTheme, 'cssVersion', $this->requireCssVersion);
$this->adminTheme->set('cssVersion', $this->requireCssVersion);
}
$this->message(implode(' ', $messages), Notice::noGroup);
} catch(\Exception $e) {
$this->error('LESS - ' . $e->getMessage(), Notice::noGroup);
}

View File

@@ -10,7 +10,7 @@ if(!defined("PROCESSWIRE_INSTALL")) die();
<!-- FOOTER -->
<footer id='pw-footer' class='uk-margin'>
<div class='pw-container uk-container uk-container-center'>
<p>ProcessWire 3.x &copy; 2020</p>
<p>ProcessWire 3.x &copy; 2021</p>
</div>
</footer>
@@ -19,4 +19,4 @@ if(!defined("PROCESSWIRE_INSTALL")) die();
</script>
</body>
</html>
</html>

View File

@@ -23,10 +23,11 @@ interface AdminThemeUikitLessInterface {
/**
* @param string $file
* @param string $url
* @return self
*
*/
public function addFile($file);
public function addFile($file, $url = '');
/**
* @param array $files
@@ -37,10 +38,11 @@ interface AdminThemeUikitLessInterface {
/**
* @param string $file
* @param array $options
* @return bool
*
*/
public function saveCss($file);
public function saveCss($file, array $options = array());
/**
* @return string