mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 03:16:11 +01:00
Added theme whitelabel export functionality
This commit is contained in:
@@ -2188,6 +2188,32 @@ class AdminController extends AdminBaseController
|
||||
|
||||
}
|
||||
|
||||
protected function taskExportScss()
|
||||
{
|
||||
if (!$this->authorizeTask('compile scss', ['admin.pages', 'admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = ['color_scheme' => $this->data['whitelabel']['color_scheme'] ?? null];
|
||||
$name = $this->data['whitelabel']['color_scheme']['name'] ?? 'theme';
|
||||
//todo slugify name
|
||||
$location = 'asset://' . $name . '.yaml';
|
||||
|
||||
[$status, $msg] = $this->grav['admin-whitelabel']->exportPresetScsss($data, $location);
|
||||
|
||||
$json_response = [
|
||||
'status' => 'success' ,
|
||||
'message' => 'Theme Export Ready',
|
||||
'files' => [
|
||||
'download' => Utils::url($location)
|
||||
]
|
||||
];
|
||||
|
||||
echo json_encode($json_response);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles deleting a media file from a page
|
||||
*
|
||||
|
||||
@@ -3,8 +3,10 @@ namespace Grav\Plugin\Admin;
|
||||
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Framework\File\File;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class WhiteLabel
|
||||
{
|
||||
@@ -66,4 +68,22 @@ class WhiteLabel
|
||||
return [false, ' Could not be recompiled, missing color scheme...'];
|
||||
}
|
||||
|
||||
public function exportPresetScsss($config, $location = 'asset://admin-theme-export.yaml')
|
||||
{
|
||||
|
||||
if (isset($config['color_scheme'])) {
|
||||
|
||||
$color_scheme = $config['color_scheme'];
|
||||
|
||||
$body = Yaml::dump($color_scheme);
|
||||
|
||||
$file = new File($location);
|
||||
$file->save($body);
|
||||
|
||||
return [true, 'File created successfully'];
|
||||
|
||||
} else {
|
||||
return [false, ' Could not export, missing color scheme...'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user