Skip to content

Commit

Permalink
Merge pull request #47 from dachcom-digital/twig_fix_upport
Browse files Browse the repository at this point in the history
[P11] add twig >= 3.9 (only) suppport
  • Loading branch information
solverat committed Apr 30, 2024
2 parents 846c725 + a2303a6 commit b7cc8f4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -9,6 +9,7 @@
### Requirements
* Pimcore: ^11.0
* PHP: >= 8.1
* Twig >= 3.9

### Release Plan

Expand All @@ -22,7 +23,7 @@

```json
"require" : {
"dachcom-digital/emailizr" : "~3.0.0",
"dachcom-digital/emailizr" : "~3.1.0",
}
```

Expand Down
4 changes: 3 additions & 1 deletion UPGRADE.md
@@ -1,5 +1,7 @@
# Upgrade Notes
--

## Version 3.1
Starting with 3.1, Emailizr only supports Twig 3.9

## Migrating from Version 2.x to Version 3.0.0
- Pimcore 11.0 support only
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -32,6 +32,7 @@
},
"require": {
"pimcore/pimcore": "^11.0",
"twig/twig": "^3.9",
"twig/inky-extra": "^3.0",
"pelago/emogrifier": "^7.0"
},
Expand Down
36 changes: 27 additions & 9 deletions src/Twig/Node/InlineStyleNode.php
Expand Up @@ -2,9 +2,12 @@

namespace EmailizrBundle\Twig\Node;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\CaptureNode;
use Twig\Node\Node;

#[YieldReady]
class InlineStyleNode extends Node
{
public function __construct(Node $html, int $line = 0, string $tag = 'inline_style')
Expand All @@ -14,15 +17,30 @@ public function __construct(Node $html, int $line = 0, string $tag = 'inline_sty

public function compile(Compiler $compiler): void
{
$node = new CaptureNode(
$this->getNode('html'),
$this->getNode('html')->lineno,
$this->getNode('html')->tag
);

$node->setAttribute('with_blocks', true);

$compiler
->write("ob_start();\n")
->subcompile($this->getNode('html'))
->write('$zurbCss = "";')
->write('foreach($context["emailizr_style_collector"] as $cssFile){')
->write('$path = $context["emailizr_locator"]->locate($cssFile);')
->write('if($path){$zurbCss .= "\n".file_get_contents($path);}')
->write('}')
->write('echo $context["emailizr_inline_style_parser"]->parseInlineHtml(ob_get_clean(), $zurbCss);')
->write('$context["emailizr_style_collector"]->removeAll();');
->write(sprintf('$inlineCssFiles = "";%s', PHP_EOL))
->write(sprintf('foreach($context["emailizr_style_collector"] as $cssFile) {%s', PHP_EOL))
->indent()
->write(sprintf('$path = $context["emailizr_locator"]->locate($cssFile);%s', PHP_EOL))
->write(sprintf('if ($path) {%s', PHP_EOL))
->indent()
->write(sprintf('$inlineCssFiles .= "\n".file_get_contents($path);%s', PHP_EOL))
->outdent()
->write(sprintf('}%s', PHP_EOL))
->outdent()
->write(sprintf('}%1$s%1$s', PHP_EOL))
->write(sprintf('$%s = ', 'inlineHtml'))
->subcompile($node)
->raw(sprintf('%1$s%1$s', PHP_EOL))
->write(sprintf('yield $context["emailizr_inline_style_parser"]->parseInlineHtml($inlineHtml, $inlineCssFiles);%s', PHP_EOL))
->write(sprintf('$context["emailizr_style_collector"]->removeAll();%1$s%1$s', PHP_EOL));
}
}

0 comments on commit b7cc8f4

Please sign in to comment.