Add theme to cache - https://github.com/humhub/humhub-internal/issues/549#issuecomment-2755998328
1
.gitignore
vendored
@ -30,6 +30,7 @@ nbproject
|
||||
|
||||
themes/*
|
||||
!themes/HumHub
|
||||
themes/HumHub/resources/css/*
|
||||
|
||||
favicon.ico
|
||||
/.settings
|
||||
|
21
Gruntfile.js
@ -108,13 +108,6 @@ module.exports = function (grunt) {
|
||||
target: {
|
||||
files: cssMinAssetcfg
|
||||
}
|
||||
},
|
||||
less: {
|
||||
dev: {
|
||||
files: {
|
||||
'themes/HumHub/css/less/theme.css': 'themes/HumHub/css/less/theme.less'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -136,20 +129,6 @@ module.exports = function (grunt) {
|
||||
* > grunt migrate-create --name=MyMigration
|
||||
*/
|
||||
grunt.registerTask('migrate-create', ['shell:migrateCreate']);
|
||||
|
||||
/**
|
||||
* Build default HumHub theme:
|
||||
*
|
||||
* > grunt build-theme
|
||||
*
|
||||
* Build named theme:
|
||||
* > grunt build-theme --name=MyTheme
|
||||
*
|
||||
* or
|
||||
*
|
||||
* > grunt shell:buildTheme:MyTheme
|
||||
*/
|
||||
grunt.registerTask('build-theme', ['shell:buildTheme']);
|
||||
grunt.registerTask('test-server', ['shell:testServer']);
|
||||
grunt.registerTask('test', ['shell:testRun']);
|
||||
};
|
||||
|
@ -698,6 +698,21 @@ Doc: https://getbootstrap.com/docs/5.3/layout/breakpoints
|
||||
|
||||
Many styles have been refactored. Please review all your overwritten CSS selectors and values.
|
||||
|
||||
### Structure
|
||||
|
||||
All theme folders must be moved to a new `resources` folder, except the `scss` and `views` folders.
|
||||
|
||||
Structure example:
|
||||
- resources
|
||||
- resources/css (empty because the CSS files are generated by the compiler, so it can be added to the `.gitignore` file)
|
||||
- resources/js/humhub.my-theme.js
|
||||
- views
|
||||
- scss/build.scss
|
||||
- scss/_mixins.scss
|
||||
- scss/_root.scss
|
||||
- scss/_theme.scss
|
||||
- scss/variables.scss
|
||||
|
||||
#### Build file
|
||||
|
||||
The `build.scss` file mustn't import the parent theme files anymore, as it is automatically done by the new compiler.
|
||||
|
@ -21,8 +21,8 @@ use yii\base\Theme as BaseTheme;
|
||||
* to see if there is a themed version of the view file exists. If so, the themed version will be rendered instead.
|
||||
* See [[ThemeViews]] for more details.
|
||||
*
|
||||
* - Using less variables
|
||||
* Using this theme class you can also access all LESS style variables of the current theme.
|
||||
* - Using scss variables
|
||||
* Using this theme class you can also access all SCSS style variables of the current theme.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
@ -51,7 +51,7 @@ class Theme extends BaseTheme
|
||||
/**
|
||||
* @var bool indicates that resources should be published via assetManager
|
||||
*/
|
||||
public $publishResources = false;
|
||||
public $publishResources = true;
|
||||
|
||||
/**
|
||||
* @var ThemeVariables
|
||||
@ -93,7 +93,7 @@ class Theme extends BaseTheme
|
||||
return $this->_baseUrl;
|
||||
}
|
||||
|
||||
$this->_baseUrl = ($this->publishResources) ? $this->publishResources() : rtrim(Yii::getAlias('@web/themes/' . $this->name), '/');
|
||||
$this->_baseUrl = $this->publishResources ? $this->publishResources() : rtrim(Yii::getAlias('@web/themes/' . $this->name), '/');
|
||||
return $this->_baseUrl;
|
||||
}
|
||||
|
||||
@ -106,9 +106,9 @@ class Theme extends BaseTheme
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_exists($this->getBasePath() . '/css/theme.css')) {
|
||||
$mtime = filemtime($this->getBasePath() . '/css/theme.css');
|
||||
Yii::$app->view->registerCssFile($this->getBaseUrl() . '/css/theme.css?v=' . $mtime, ['depends' => CoreBundleAsset::class]);
|
||||
if (file_exists($this->getBasePath() . '/resources/css/theme.css')) {
|
||||
$mtime = filemtime($this->getBasePath() . '/resources/css/theme.css');
|
||||
Yii::$app->view->registerCssFile($this->getBaseUrl() . '/resources/css/theme.css?v=' . $mtime, ['depends' => CoreBundleAsset::class]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,12 +181,12 @@ class Theme extends BaseTheme
|
||||
public function publishResources($force = null)
|
||||
{
|
||||
if ($force === null) {
|
||||
$force = (YII_DEBUG);
|
||||
$force = YII_DEBUG;
|
||||
}
|
||||
|
||||
$published = Yii::$app->assetManager->publish(
|
||||
$this->getBasePath(),
|
||||
['forceCopy' => $force, 'except' => ['views/']],
|
||||
['forceCopy' => $force, 'except' => ['views/', 'scss/']],
|
||||
);
|
||||
|
||||
return $published[1];
|
||||
|
@ -16,6 +16,7 @@ use ScssPhp\ScssPhp\Exception\SassException;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\FileHelper;
|
||||
|
||||
/**
|
||||
* ThemeHelper
|
||||
@ -57,10 +58,7 @@ class ThemeHelper
|
||||
if (is_dir($moduleThemePath)) {
|
||||
$themes = ArrayHelper::merge(
|
||||
$themes,
|
||||
self::getThemesByPath(
|
||||
$moduleThemePath,
|
||||
['publishResources' => true],
|
||||
),
|
||||
self::getThemesByPath($moduleThemePath),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -106,10 +104,9 @@ class ThemeHelper
|
||||
try {
|
||||
/** @var Theme $theme */
|
||||
$theme = Yii::createObject(ArrayHelper::merge([
|
||||
'class' => 'humhub\components\Theme',
|
||||
'class' => Theme::class,
|
||||
'basePath' => $path,
|
||||
'name' => basename($path),
|
||||
'publishResources' => (dirname($path) !== Yii::getAlias('@themes')),
|
||||
], $options));
|
||||
} catch (InvalidConfigException $e) {
|
||||
Yii::error('Could not get theme by path "' . $path . '" - Error: ' . $e->getMessage());
|
||||
@ -260,8 +257,16 @@ class ThemeHelper
|
||||
]);
|
||||
|
||||
// Define the output files
|
||||
$cssFilePath = $theme->getBasePath() . '/css/theme.css';
|
||||
$mapFilePath = $theme->getBasePath() . '/css/theme.map';
|
||||
$resourcesDir = $theme->getBasePath() . '/resources';
|
||||
if (!file_exists($theme->getBasePath() . '/resources')) {
|
||||
FileHelper::createDirectory($resourcesDir);
|
||||
}
|
||||
$cssDir = $resourcesDir . '/css';
|
||||
if (!file_exists($cssDir)) {
|
||||
FileHelper::createDirectory($cssDir);
|
||||
}
|
||||
$cssFilePath = $cssDir . '/theme.css';
|
||||
$mapFilePath = $cssDir . '/theme.map';
|
||||
$errorMsgStart = Yii::t('UiModule.base', 'Cannot compile SCSS to CSS code.');
|
||||
|
||||
// Check if files are writable
|
||||
@ -291,7 +296,8 @@ class ThemeHelper
|
||||
file_put_contents($cssFilePath, $result->getCss()) !== false
|
||||
&& file_put_contents($mapFilePath, $result->getSourceMap()) !== false
|
||||
) {
|
||||
Yii::$app->assetManager->clear();
|
||||
$theme->publishResources(true);
|
||||
$theme->variables->flushCache();
|
||||
return true;
|
||||
}
|
||||
} catch (SassException $e) {
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
namespace humhub\modules\admin\models\forms;
|
||||
|
||||
use humhub\components\ThemeVariables;
|
||||
use humhub\helpers\ThemeHelper;
|
||||
use humhub\libs\DynamicConfig;
|
||||
use humhub\libs\LogoImage;
|
||||
@ -53,6 +52,7 @@ class DesignSettingsForm extends Model
|
||||
parent::init();
|
||||
|
||||
$settingsManager = Yii::$app->settings;
|
||||
$themeVariables = Yii::$app->view->theme->variables;
|
||||
|
||||
$this->theme = Yii::$app->view->theme->name;
|
||||
$this->paginationSize = $settingsManager->get('paginationSize');
|
||||
@ -62,9 +62,9 @@ class DesignSettingsForm extends Model
|
||||
$this->dateInputDisplayFormat = Yii::$app->getModule('admin')->settings->get('defaultDateInputFormat');
|
||||
$this->horImageScrollOnMobile = $settingsManager->get('horImageScrollOnMobile');
|
||||
$this->defaultStreamSort = Yii::$app->getModule('stream')->settings->get('defaultSort');
|
||||
$this->themePrimaryColor = $settingsManager->get('themePrimaryColor', Yii::$app->view->theme->variables->get('primary'));
|
||||
$this->themePrimaryColor = $settingsManager->get('themePrimaryColor', $themeVariables->get('primary'));
|
||||
$this->useDefaultThemePrimaryColor = (bool)$settingsManager->get('useDefaultThemePrimaryColor', true);
|
||||
$this->themeSecondaryColor = $settingsManager->get('themeSecondaryColor', Yii::$app->view->theme->variables->get('secondary'));
|
||||
$this->themeSecondaryColor = $settingsManager->get('themeSecondaryColor', $themeVariables->get('secondary'));
|
||||
$this->useDefaultThemeSecondaryColor = (bool)$settingsManager->get('useDefaultThemeSecondaryColor', true);
|
||||
$this->themeCustomScss = $settingsManager->get('themeCustomScss');
|
||||
}
|
||||
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 972 B After Width: | Height: | Size: 972 B |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |