-
Notifications
You must be signed in to change notification settings - Fork 11
Enhancement: More flexible bootstrap #4
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
Conversation
This will allow to initialize plugin this way:
```php
new CssInlinerPlugin([
'useInlineStylesBlock' => true,
'cleanup' => true,
'stripOriginalStyleTags' => true,
]);
```
Actually I suggest it for compatibility with Yii2 framework. With this change it's possible to enable CssInlinerPlugin in this easy way:
```php
return [
'components' => [
[...]
/**
* Mailer
*
* @link https://github.com/yiisoft/yii2-swiftmailer
* @link http://swiftmailer.org/docs/messages.html
*/
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'messageConfig' => [
'charset' => 'utf-8',
],
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mail.domain.com',
'username' => 'support@domain.com',
'password' => '...',
'plugins' => [
[
'class' => 'Openbuildings\Swiftmailer\CssInlinerPlugin',
'constructArgs' => [[
'cleanup' => true,
'useInlineStylesBlock' => true,
'stripOriginalStyleTags' => true,
]],
],
],
],
],
],
];
```
I believe that will be good addition to existing implementation when CssToInlineStyles object is passed to class constructor as parameter.
|
That's nice! Thanks! I would actually go with an approach which does not use dynamic parameters. Something like: new CssInlinerPlugin($converter, [
'cleanup' => true,
'useInlineStylesBlock' => true,
'stripOriginalStyleTags' => true,
]);
// or if you don't want to create a converter instance:
new CssInlinerPlugin(null, [
'cleanup' => true,
'useInlineStylesBlock' => true,
'stripOriginalStyleTags' => true,
]);Another thing is the default setting here: https://github.com/OpenBuildings/swiftmailer-css-inliner/pull/4/files#diff-03ae371a6f0335442e7b7fc7aa1cd3beL32 $this->converter->setUseInlineStylesBlock(TRUE);Why not having a property in the protected $config = array(
'useInlineStylesBlock' => TRUE,
);And if there is a second argument passed to the constructor it will be merged with the default and then this config will be iterated and set like you've done it. |
|
With default configuration looks even better, |
|
Check it |
|
@armab Great! Could you update it to support PHP 5.3 as it was before? The short array literal syntax is nice, but this is the only reason this is not working on PHP 5.3. |
|
Done. Sorry, |
|
I see Unit Tests failed. In this example: new CssInlinerPlugin($converter);should default And what's about this example ?: new CssInlinerPlugin($converter, array(
'cleanup' => true,
'stripOriginalStyleTags' => true,
));Or maybe default What do you think would be good behaviour? I feel like we added more unneeded complexity with second parameter, instead of one dynamic one) For example this looks weird: new CssInlinerPlugin($converter, array(
'cleanup' => true,
'stripOriginalStyleTags' => true,
));If converter already passed usually it was already constructed and there is no need of additional rules in array. And this new CssInlinerPlugin(null, array(
'cleanup' => true,
'stripOriginalStyleTags' => true,
));I'm better with default $config in class and one dynamic parameter (not 2). |
|
Final version with single dynamic parameter. |
|
Hi - 10x very much for all this support, this is an incredibly great discussion. I have several points to contribute:
So turn all of these suggestions into actionable advice, what we can do with this pull request is:
How does that sound? We could do this ourselves but it would take time as there's a lot of other work at the moment, so you can do it yourself it would probably be faster. If this is implemented and merged we'll release it as 0.2 as it will be a breaking change, so it will not affect people that depend on the current implementation. And again thanks very much for contributing, its really great watching OSS at work. |
|
I don't think additional file that will implement all this stuff is good way. This plugin is just simple wrapper for other class, no need of additional files. Here is another implementation that gives possibility to call setters of $plugin = new Openbuildings\Swiftmailer\CssInlinerPlugin();
$plugin->setUseInlineStylesBlock(true);
$plugin->setCleanup(true);
$plugin->setStripOriginalStyleTags(true);That's even more flexible, because it gives possibility to manipulate And Yii2 config to bootstrap/use this plugin will look this way: return [
'components' => [
[...]
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'plugins' => [
[
'class' => 'Openbuildings\Swiftmailer\CssInlinerPlugin',
'cleanup' => true, // if plugin property with such name nonexistent, Yii2 will try to call setter 'setcleanup(true)' instead
'useInlineStylesBlock' => true,
'stripOriginalStyleTags' => true,
]
],
],
],
],
]; |
|
@armab Actually having properties instead of an array config makes sense. The configuration would not be hidden in string keys. However it would be strange that this property does not anything other than sit there. Anyways, a big 👍 for multiple setters. |
|
@armab Hello again! Do you think you would be able to rebase this to fix the conflicts and possibly squash the commits into one? A section in the readme for Yii configuration would be really nice as well. Thank you! |
|
@hkdobrev, nope. |
|
Superseded by #3 using composition instead of array config. |
This will allow apart of 'converter injection' to initialize plugin this way:
which is equivalent of this:
Actually I suggest it for compatibility with Yii2 framework. With this change it's possible to enable CssInlinerPlugin in this easy way in Yii2 config file:
Existing implementation when CssToInlineStyles object is injected is already perfect.
I believe this change will be good addition that allow to use plugin in more flexible way (maybe other frameworks).
Thanks!