Skip to content

Commit

Permalink
add trimwhitespace config (#4531)
Browse files Browse the repository at this point in the history
* add trimwhitespace config
  • Loading branch information
craigh authored Oct 18, 2020
1 parent 4c1b639 commit cc3fea9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fixes:
- [CoreBundle] Added clearing of OPCache (if in use) to standard clearcache operation (#4507).
- [ThemeModule] Asset combination now defaults to `false` on installation (#4419).
- [ThemeModule] Corrected missing configurable value for `trimwhitespace` option ().

- Features:
- [config] Added standard Symfony bundle configurations for the following bundles (#4433):
Expand Down
1 change: 1 addition & 0 deletions docs/Configuration/BundleConfig/Defaults/zikula_theme.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# These are the default values
zikula_theme:
script_position: foot
trimwhitespace: false
bootstrap:
css_path: '/bootstrap/css/bootstrap.min.css'
js_path: '/bootstrap/js/bootstrap.bundle.min.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
->values(['head', 'foot'])
->defaultValue('foot')
->end()
->booleanNode('trimwhitespace')->defaultFalse()->end()
->arrayNode('bootstrap')
->addDefaultsIfNotSet()
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Zikula\ThemeModule\EventListener\DefaultPageAssetSetterListener;
use Zikula\ThemeModule\EventListener\ExtensionInstallationListener;
use Zikula\ThemeModule\EventListener\HookChangeListener;
use Zikula\ThemeModule\EventListener\ResponseTransformerListener;

class ZikulaThemeExtension extends Extension
{
Expand All @@ -37,6 +38,8 @@ public function load(array $configs, ContainerBuilder $container)

$container->getDefinition(AssetFilter::class)
->setArgument('$scriptPosition', $config['script_position']);
$container->getDefinition(ResponseTransformerListener::class)
->setArgument('$trimWhitespace', $config['trimwhitespace']);

$container->getDefinition(ExtensionInstallationListener::class)
->setArgument('$mergerActive', $config['asset_manager']['combine']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
use Zikula\ThemeModule\Engine\ResponseTransformer;

class ResponseTransformerListener implements EventSubscriberInterface
{
/**
* @var VariableApiInterface
* @var bool
*/
private $variableApi;
private $trimWhitespace;

public function __construct(VariableApiInterface $variableApi)
public function __construct(bool $trimWhitespace = false)
{
$this->variableApi = $variableApi;
$this->trimWhitespace = $trimWhitespace;
}

public static function getSubscribedEvents()
Expand All @@ -47,8 +46,7 @@ public function transformResponse(ResponseEvent $event): void
}

$response = $event->getResponse();
$trimWhitespace = $this->variableApi->get('ZikulaThemeModule', 'trimwhitespace');
if ($trimWhitespace) {
if ($this->trimWhitespace) {
$responseTransformer = new ResponseTransformer();
$responseTransformer->trimWhitespace($response);
}
Expand Down
27 changes: 2 additions & 25 deletions src/system/ThemeModule/ThemeModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,6 @@ class ThemeModuleInstaller extends AbstractExtensionInstaller
{
public function install(): bool
{
// define defaults for module vars
$this->setVar('modulesnocache');
$this->setVar('enablecache', false);
$this->setVar('compile_check', true);
$this->setVar('cache_lifetime', 1800);
$this->setVar('cache_lifetime_mods', 1800);
$this->setVar('force_compile', false);
$this->setVar('trimwhitespace', false);
$this->setVar('maxsizeforlinks', 30);
$this->setVar('itemsperpage', 25);

$this->setVar('cssjscombine', false);
$this->setVar('cssjscompress', false);
$this->setVar('cssjsminify', false);
$this->setVar('cssjscombine_lifetime', 3600);

// View
$this->setVar('render_compile_check', true);
$this->setVar('render_force_compile', false);
$this->setVar('render_cache', false);
$this->setVar('render_expose_template', false);
$this->setVar('render_lifetime', 3600);

// Initialisation successful
return true;
}

Expand All @@ -53,7 +29,8 @@ public function upgrade(string $oldVersion): bool
// version number reset to 3.0.0 at Core 3.0.0
switch ($oldVersion) {
case '2.9.9':
// nothing to do
case '3.0.99':
$this->delVars();
}

return true;
Expand Down

0 comments on commit cc3fea9

Please sign in to comment.