Skip to content

Commit 0afe389

Browse files
committed
Merge pull request #2 from caxy/feature-1-twig_extension
Added Twig Extension
2 parents f0d256c + 09ec26e commit 0afe389

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

Resources/config/services.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
parameters:
22
caxy.html_diff.class: Caxy\HtmlDiffBundle\Service\HtmlDiffService
3+
caxy.twig.html_diff_extension.class: Caxy\HtmlDiffBundle\Twig\HtmlDiffExtension
34

45
services:
56
caxy.html_diff:
67
class: %caxy.html_diff.class%
7-
arguments: [@service_container]
8+
arguments: [@service_container]
9+
caxy.twig.html_diff_extension:
10+
class: %caxy.twig.html_diff_extension.class%
11+
arguments: [@service_container]
12+
tags:
13+
- { name: twig.extension }

Twig/HtmlDiffExtension.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Caxy\HtmlDiffBundle\Twig;
4+
5+
use Symfony\Component\DependencyInjection\ContainerInterface;
6+
7+
class HtmlDiffExtension extends \Twig_Extension
8+
{
9+
protected $container;
10+
11+
protected $htmlDiff;
12+
13+
public function __construct(ContainerInterface $container)
14+
{
15+
$this->container = $container;
16+
$this->htmlDiff = $this->container->get('caxy.html_diff');
17+
}
18+
19+
public function getFunctions()
20+
{
21+
return array(
22+
new \Twig_SimpleFunction('htmldiff', array($this, 'htmlDiff')),
23+
);
24+
}
25+
26+
public function htmlDiff($a, $b)
27+
{
28+
return $this->htmlDiff->diff((string) $a, (string) $b);
29+
}
30+
31+
public function getName()
32+
{
33+
return 'caxy_htmldiff_extension';
34+
}
35+
}

0 commit comments

Comments
 (0)