mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-28 00:36:36 +01:00
optimizations + fixes
This commit is contained in:
@@ -610,8 +610,13 @@ class AdminPlugin extends Plugin
|
||||
$assets->setJsPipeline(false);
|
||||
$assets->setCssPipeline(false);
|
||||
|
||||
// Whitebox logic
|
||||
$this->grav['admin-whitebox']->compileScss($this->config->get('plugins.admin.whitebox'), true);
|
||||
// Compile a missing preset.css file
|
||||
$preset_css = 'plugin://admin/themes/grav/css-compiled/preset.css';
|
||||
$preset_path = $this->grav['locator']->findResource($preset_css);
|
||||
if (!$preset_path) {
|
||||
$this->grav['admin-whitebox']->compileScss($this->config->get('plugins.admin.whitebox'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2156,33 +2156,29 @@ class AdminController extends AdminBaseController
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function tasCompileScss()
|
||||
protected function taskCompileScss()
|
||||
{
|
||||
|
||||
if (!$this->authorizeTask('compile scss', ['admin.pages', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$uri = $this->grav['uri'];
|
||||
$preview = $this->grav['uri']->post('preview');
|
||||
$data = $uri->post('data');
|
||||
|
||||
$data = ['color_scheme' => $data['color_scheme']];
|
||||
$preview = $this->data['preview'] ?? false;
|
||||
$data = ['color_scheme' => $this->data['color_scheme'] ?? null];
|
||||
|
||||
if ($preview) {
|
||||
// send through some tmp filenames
|
||||
$this->grav['admin-whitebox']->compileScss($data, false, ['preset'=>'preset_tmp']);
|
||||
[$compile_status, $msg] = $this->grav['admin-whitebox']->compileScss($data, ['filename' => 'preset_tmp']);
|
||||
} else {
|
||||
$this->grav['admin-whitebox']->compileScss($data);
|
||||
[$compile_status, $msg] = $this->grav['admin-whitebox']->compileScss($data);
|
||||
}
|
||||
|
||||
$previewSuffix = $preview ? '_tmp' : '';
|
||||
|
||||
$json_response = [
|
||||
'status' => 'success',
|
||||
'message' => ($preview ? 'Preview' : 'SCSS') . ' Recompiled Successfully',
|
||||
'status' => $compile_status ? 'success' : 'error',
|
||||
'message' => ($preview ? 'Preview ' : 'SCSS ') . $msg,
|
||||
'files' => [
|
||||
'color_scheme' => $uri->rootUrl() . "/user/plugins/admin/css-compiled/preset${previewSuffix}.css"
|
||||
'color_scheme' => $this->grav['twig']->twig_vars['base_url_relative']. "/user/plugins/admin/themes/grav/css-compiled/preset${previewSuffix}.css"
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -14,16 +14,12 @@ class Whitebox
|
||||
$this->scss = new ScssCompiler();
|
||||
}
|
||||
|
||||
public function compileScss($config, $check_exists = false, $filenames = null)
|
||||
public function compileScss($config, $options = ['filename' => 'preset'])
|
||||
{
|
||||
if (is_array($config)) {
|
||||
$color_scheme = $config['color_scheme'];
|
||||
} else {
|
||||
$color_scheme = $config->get('color_scheme');
|
||||
}
|
||||
|
||||
if (!$filenames) {
|
||||
$filenames['preset'] = 'preset';
|
||||
$color_scheme = $config->get('whitebox.color_scheme');
|
||||
}
|
||||
|
||||
if ($color_scheme) {
|
||||
@@ -34,15 +30,14 @@ class Whitebox
|
||||
$custom_out_base = $locator->findResource('plugin://admin/themes/grav/css-compiled');
|
||||
|
||||
$preset_in_path = $admin_in_base .'/preset.scss';
|
||||
$preset_out_path = $custom_out_base . '/'.$filenames['preset'].'.css';
|
||||
$preset_out_path = $custom_out_base . '/'. $options['filename'] . '.css';
|
||||
|
||||
if (!$check_exists ||
|
||||
($check_exists && !file_exists($preset_out_path))) {
|
||||
|
||||
// do stuff with the color scheme
|
||||
$this->compilePresetScss($color_scheme, $preset_in_path, $preset_out_path);
|
||||
|
||||
return [true, 'Recompiled successfully'];
|
||||
|
||||
}
|
||||
}
|
||||
return [false, ' Could not be recompiled, missing color scheme...'];
|
||||
}
|
||||
|
||||
public function compilePresetScss($colors, $in_path, $out_path)
|
||||
|
||||
1301
themes/grav/css-compiled/preset.css
vendored
1301
themes/grav/css-compiled/preset.css
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user