Skip to content

Commit

Permalink
Add Overridable Parameter Containing Path to Public Directory
Browse files Browse the repository at this point in the history
- Adds `css_to_inline_email_twig_extension.public_dir` parameter containing path to public directory
  (default remains as `web` just outside kernel root)
- Removes unused `use` statements
- Adds twig as dev dependency
  • Loading branch information
David Cochrum committed Sep 14, 2018
1 parent 95a454c commit 7d3fa8b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
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.public_dir` 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.public_dir">%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.public_dir%</argument>
<argument>%kernel.debug%</argument>
<tag name="twig.extension" />
</service>
Expand Down
9 changes: 4 additions & 5 deletions Twig/InlineCssExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,7 +23,7 @@ class InlineCssExtension extends \Twig_Extension implements \Twig_Extension_Glob
/**
* @var string
*/
private $kernelRoot;
private $webRoot;
/**
* @var FileLocatorInterface
*/
Expand All @@ -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;
}

Expand All @@ -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));
}

/**
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

0 comments on commit 7d3fa8b

Please sign in to comment.