|
6 | 6 | */ |
7 | 7 | namespace RobertoTru\ToInlineStyleEmailBundle\Twig; |
8 | 8 |
|
9 | | -use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; |
10 | | -use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; |
11 | 9 | use Symfony\Component\Config\FileLocatorInterface; |
12 | 10 | use Symfony\Component\Templating\TemplateNameParserInterface; |
13 | 11 | use Twig_NodeInterface; |
|
16 | 14 | class InlineCssParser extends \Twig_TokenParser |
17 | 15 | { |
18 | 16 | /** |
19 | | - * @var \Symfony\Component\Templating\TemplateNameParserInterface |
| 17 | + * @var TemplateNameParserInterface |
20 | 18 | */ |
21 | 19 | private $templateNameParser; |
| 20 | + |
22 | 21 | /** |
23 | | - * @var \Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator |
| 22 | + * @var FileLocatorInterface |
24 | 23 | */ |
25 | 24 | private $locator; |
| 25 | + |
26 | 26 | /** |
27 | | - * @var \Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser |
| 27 | + * @var string |
28 | 28 | */ |
29 | | - private $name_parser; |
| 29 | + protected $webRoot; |
| 30 | + |
30 | 31 | /** |
31 | 32 | * @var bool |
32 | 33 | */ |
33 | 34 | private $debug; |
34 | 35 |
|
35 | 36 | /** |
36 | 37 | * @param FileLocatorInterface $locator used to get css asset real path |
| 38 | + * @param TemplateNameParserInterface $templateNameParser |
37 | 39 | * @param string $webRoot web root of the project |
38 | 40 | * @param bool $debug in debug mode css is not inlined but read on each render |
39 | 41 | */ |
40 | | - public function __construct(FileLocatorInterface $locator, $name_parser, $webRoot, $debug = false) |
| 42 | + public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $templateNameParser, $webRoot, $debug = false) |
41 | 43 | { |
42 | 44 | $this->locator = $locator; |
43 | | - $this->name_parser = $name_parser; |
| 45 | + $this->templateNameParser = $templateNameParser; |
44 | 46 | $this->webRoot = $webRoot; |
45 | 47 | $this->debug = $debug; |
46 | 48 | } |
@@ -88,10 +90,10 @@ public function decideEnd(Twig_Token $token) |
88 | 90 | private function resolvePath($path) |
89 | 91 | { |
90 | 92 | try { |
91 | | - return $this->locator->locate($this->name_parser->parse($path)); |
| 93 | + return $this->locator->locate($this->templateNameParser->parse($path)); |
92 | 94 | } catch (\InvalidArgumentException $e) { |
93 | 95 | //happens when path is not bundle relative |
94 | | - return $path; |
| 96 | + return $this->webRoot.'/'.$path; |
95 | 97 | } |
96 | 98 | } |
97 | 99 | } |
0 commit comments