From 2daaf1c2604d9292b41802925c4d6835f94006ef Mon Sep 17 00:00:00 2001 From: David Cochrum Date: Fri, 14 Sep 2018 15:44:34 -0400 Subject: [PATCH 1/2] Add Overridable Parameter Containing Path to Web Root Directory - Adds `css_to_inline_email_twig_extension.web_root` parameter containing path to web root directory (default remains as `web` just outside kernel root) - Removes unused `use` statements - Adds twig as dev dependency --- .gitignore | 1 + README.md | 6 +++++- Resources/config/services.xml | 3 ++- Twig/InlineCssExtension.php | 9 ++++----- Twig/InlineCssParser.php | 1 - composer.json | 5 +++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 8ca34de..cdd91d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea phpunit.xml composer.lock /vendor diff --git a/README.md b/README.md index 93055ad..70d14bd 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ $converter->setHTMLByView( ); ``` -The preceding function must be used _in vece_ of function ```setHTML()```. +The preceding function must be used _instead_ of ```setHTML()```. To use the ```generateStyledHTML``` method just use it like: @@ -121,6 +121,10 @@ Dynamic variable is supported (Use absolute path with variable with asset or dir Read the docs in the files for further details on the usage of the service. +Configuration +============= +The `css_to_inline_email_twig_extension.web_root` parameter contains the path to the root directory accessible to the web. This path is assumed to be a `web` directory just outside the kernel root directory as recommended in Symfony 2-3 (`%kernel.root_dir%/../web`). With Symfony 4, the recommended path moved to a `public` directory just outside the kernel root directory (`%kernel.root_dir%/../public`). Override the parameter with the correct path for your implementation. + Contributing ============ **ToInlineStyleEmailBundle** is an open source project, under MIT license. Contributions are encouraged. diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 45624cc..495b198 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -7,6 +7,7 @@ RobertoTru\ToInlineStyleEmailBundle\Converter\ToInlineStyleEmailConverter RobertoTru\ToInlineStyleEmailBundle\Twig\InlineCssExtension + %kernel.root_dir%/../web @@ -16,7 +17,7 @@ - %kernel.root_dir% + %css_to_inline_email_twig_extension.web_root% %kernel.debug% diff --git a/Twig/InlineCssExtension.php b/Twig/InlineCssExtension.php index 135222c..dfbe865 100644 --- a/Twig/InlineCssExtension.php +++ b/Twig/InlineCssExtension.php @@ -13,7 +13,6 @@ use RobertoTru\ToInlineStyleEmailBundle\Converter\ToInlineStyleEmailConverter; use Symfony\Component\Config\FileLocatorInterface; -use Symfony\Component\Templating\TemplateNameParserInterface; class InlineCssExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface { @@ -24,7 +23,7 @@ class InlineCssExtension extends \Twig_Extension implements \Twig_Extension_Glob /** * @var string */ - private $kernelRoot; + private $webRoot; /** * @var FileLocatorInterface */ @@ -37,12 +36,12 @@ class InlineCssExtension extends \Twig_Extension implements \Twig_Extension_Glob public function __construct( ToInlineStyleEmailConverter $inlineCss, FileLocatorInterface $locator, - $kernelRoot, + $webRoot, $debug = false ) { $this->inlineCss = $inlineCss; $this->locator = $locator; - $this->kernelRoot = $kernelRoot; + $this->webRoot = $webRoot; $this->debug = $debug; } @@ -51,7 +50,7 @@ public function __construct( */ public function getTokenParsers() { - return array(new InlineCssParser($this->locator, $this->kernelRoot . '/../web', $this->debug)); + return array(new InlineCssParser($this->locator, $this->webRoot, $this->debug)); } /** diff --git a/Twig/InlineCssParser.php b/Twig/InlineCssParser.php index 89a9b16..b6c1ff5 100644 --- a/Twig/InlineCssParser.php +++ b/Twig/InlineCssParser.php @@ -12,7 +12,6 @@ namespace RobertoTru\ToInlineStyleEmailBundle\Twig; use Symfony\Component\Config\FileLocatorInterface; -use Symfony\Component\Templating\TemplateNameParserInterface; use Twig_Node; use Twig_Token; diff --git a/composer.json b/composer.json index a5ef580..b298773 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "gushphp/to-inline-style-email-bundle", "type": "symfony-bundle", - "description": "A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen", + "description": "A Symfony bundle for using the CssToInlineStyles translator by tijsverkoyen", "keywords": ["css", "inline", "style", "email", "symfony", "bundle"], "homepage": "http://github.com/gushphp/ToInlineStyleEmailBundle", "license": "MIT", @@ -19,7 +19,8 @@ }, "require-dev": { "symfony/framework-bundle": "*", - "phpunit/phpunit": "^4.4" + "phpunit/phpunit": "^4.4", + "twig/twig": "*" }, "autoload": { "psr-4": { "RobertoTru\\ToInlineStyleEmailBundle\\": "" } From 1c51f8ac4f8e592c4e86c1f7fb2e42ba3df637f0 Mon Sep 17 00:00:00 2001 From: Cristiano da Silva Date: Mon, 11 Nov 2019 09:46:23 -0500 Subject: [PATCH 2/2] Fix deprecated twig error message ``` php.INFO: User Deprecated: Using the "Twig_Extension_GlobalsInterface" class is deprecated since Twig version 2.7, use "Twig\Extension\GlobalsInterface" instead."} ``` --- Twig/InlineCssExtension.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Twig/InlineCssExtension.php b/Twig/InlineCssExtension.php index dfbe865..b78870b 100644 --- a/Twig/InlineCssExtension.php +++ b/Twig/InlineCssExtension.php @@ -13,21 +13,30 @@ use RobertoTru\ToInlineStyleEmailBundle\Converter\ToInlineStyleEmailConverter; use Symfony\Component\Config\FileLocatorInterface; +use Twig\Extension\GlobalsInterface as TwigExtensionGlobalsInterface; -class InlineCssExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface +/** + * Responsible to construct the instance responsible to inject the inline csss. + * + * @package RobertoTru\ToInlineStyleEmailBundle\Twig + */ +class InlineCssExtension extends \Twig_Extension implements TwigExtensionGlobalsInterface { /** * @var ToInlineStyleEmailConverter */ private $inlineCss; + /** * @var string */ private $webRoot; + /** * @var FileLocatorInterface */ private $locator; + /** * @var bool */ @@ -40,9 +49,9 @@ public function __construct( $debug = false ) { $this->inlineCss = $inlineCss; - $this->locator = $locator; - $this->webRoot = $webRoot; - $this->debug = $debug; + $this->locator = $locator; + $this->webRoot = $webRoot; + $this->debug = $debug; } /**