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

Add Overridable Parameter Containing Path to Public Directory #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
phpunit.xml
composer.lock
/vendor
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<parameters>
<parameter key="css_to_inline_email_converter.class">RobertoTru\ToInlineStyleEmailBundle\Converter\ToInlineStyleEmailConverter</parameter>
<parameter key="css_to_inline_email_twig_extension.class">RobertoTru\ToInlineStyleEmailBundle\Twig\InlineCssExtension</parameter>
<parameter key="css_to_inline_email_twig_extension.web_root">%kernel.root_dir%/../web</parameter>
</parameters>

<services>
Expand All @@ -16,7 +17,7 @@
<service id="css_to_inline_email_twig_extension" class="%css_to_inline_email_twig_extension.class%">
<argument type="service" id="css_to_inline_email_converter" />
<argument type="service" id="file_locator" />
<argument>%kernel.root_dir%</argument>
<argument>%css_to_inline_email_twig_extension.web_root%</argument>
<argument>%kernel.debug%</argument>
<tag name="twig.extension" />
</service>
Expand Down
24 changes: 16 additions & 8 deletions Twig/InlineCssExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -37,21 +45,21 @@ 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;
}

/**
* {@inheritDoc}
*/
public function getTokenParsers()
{
return array(new InlineCssParser($this->locator, $this->kernelRoot . '/../web', $this->debug));
return array(new InlineCssParser($this->locator, $this->webRoot, $this->debug));
}

/**
Expand Down
1 change: 0 additions & 1 deletion Twig/InlineCssParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace RobertoTru\ToInlineStyleEmailBundle\Twig;

use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Twig_Node;
use Twig_Token;

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -19,7 +19,8 @@
},
"require-dev": {
"symfony/framework-bundle": "*",
"phpunit/phpunit": "^4.4"
"phpunit/phpunit": "^4.4",
"twig/twig": "*"
},
"autoload": {
"psr-4": { "RobertoTru\\ToInlineStyleEmailBundle\\": "" }
Expand Down