Skip to content

Commit

Permalink
[TwigHooks] Add a possibility to disable autoprefixing using the conf…
Browse files Browse the repository at this point in the history
…iguration file
  • Loading branch information
jakubtobiasz committed Apr 23, 2024
1 parent fe9275f commit d7b5977
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/TwigHooks/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
->args([
service('twig_hooks.renderer.hook'),
service('twig_hooks.hook.name_generator.template'),
param('twig_hooks.enable_autoprefixing'),
])
->tag('twig.runtime')
;
Expand Down
6 changes: 6 additions & 0 deletions src/TwigHooks/src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
->booleanNode('enable_autoprefixing')->defaultFalse()->end()
->end()
->end();

$this->addSupportedHookableTypesConfiguration($rootNode);
$this->addHooksConfiguration($rootNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function load(array $configs, ContainerBuilder $container): void
$config = $this->processConfiguration($configuration, $configs);

$this->registerHooks($container, $config['hooks'], $config['supported_hookable_types']);
$container->setParameter('twig_hooks.enable_autoprefixing', $config['enable_autoprefixing']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TwigHooks/src/Twig/Runtime/HooksRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class HooksRuntime implements RuntimeExtensionInterface
public function __construct (
private readonly HookRendererInterface $hookRenderer,
private readonly NameGeneratorInterface $nameGenerator,
private readonly bool $enableAutoprefixing = true,
private readonly bool $enableAutoprefixing,
) {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
twig_hooks:
enable_autoprefixing: true
hooks:
'hook_with_hookable':
hookable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public function testItReturnsDefaultConfiguration(): void
[],
[
'hooks' => [],
'enable_autoprefixing' => false,
'supported_hookable_types' => [
'template' => HookableTemplate::class,
'component' => HookableComponent::class,
],
],
'hooks.*'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@

final class TwigHooksExtensionTest extends AbstractExtensionTestCase
{
public function testItSetsEnableAutoprefixingParameter(): void
{
$this->load([
'enable_autoprefixing' => true,
'hooks' => [],
'supported_hookable_types' => [],
]);

$this->assertContainerBuilderHasParameter('twig_hooks.enable_autoprefixing', true);
}

public function testItRegistersHookablesAsServices(): void
{
$this->load([
Expand Down

0 comments on commit d7b5977

Please sign in to comment.