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..b78870b 100644 --- a/Twig/InlineCssExtension.php +++ b/Twig/InlineCssExtension.php @@ -13,22 +13,30 @@ use RobertoTru\ToInlineStyleEmailBundle\Converter\ToInlineStyleEmailConverter; use Symfony\Component\Config\FileLocatorInterface; -use Symfony\Component\Templating\TemplateNameParserInterface; +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 $kernelRoot; + private $webRoot; + /** * @var FileLocatorInterface */ private $locator; + /** * @var bool */ @@ -37,13 +45,13 @@ 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->debug = $debug; + $this->locator = $locator; + $this->webRoot = $webRoot; + $this->debug = $debug; } /** @@ -51,7 +59,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\\": "" }