Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P11] add twig >= 3.9 (only) suppport #47

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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));
}
}
Loading