Skip to content

Commit 9d73c6c

Browse files
committed
Add Twig extension for Haste formatter
1 parent fe59981 commit 9d73c6c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

config/services.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ services:
4040
$entityManager: '@?doctrine.orm.entity_manager'
4141
public: true
4242

43+
Codefog\HasteBundle\Twig\HasteExtension: ~
44+
4345
# StringParser
4446
Codefog\HasteBundle\StringParser:
4547
public: true

src/Twig/HasteExtension.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codefog\HasteBundle\Twig;
6+
7+
use Codefog\HasteBundle\Formatter;
8+
use Twig\Extension\AbstractExtension;
9+
use Twig\TwigFunction;
10+
11+
class HasteExtension extends AbstractExtension
12+
{
13+
public function __construct(private readonly Formatter $formatter)
14+
{
15+
}
16+
17+
public function getFunctions(): array
18+
{
19+
return [
20+
new TwigFunction('dca_label', $this->formatter->dcaLabel(...)),
21+
new TwigFunction('dca_value', $this->formatter->dcaValue(...)),
22+
];
23+
}
24+
}

0 commit comments

Comments
 (0)