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

[FEATURE] Add isRemoveDisplayNoneEnabled option + tests #162

Conversation

timothyasp
Copy link
Contributor

This adds an options parameter and some tests for a isRemoveDisplayNoneEnabled option
which specifies if the Emogrifier parser will remove elements with the style
"display: none".

Unfortunatly, the nice little optimization has some consiquences.

When writing responsive email templates, "display: none" is used often to hide
certain sections of the template for desktop email clients and show them in
phone clients.

I can see how it'd be nice to clean up elements that will not be displayed in
some cases, so that's why I made it an options field.

@timothyasp timothyasp force-pushed the add-remove-display-none-as-option branch 2 times, most recently from b706250 to f2d81ad Compare May 15, 2015 19:57
* Determines whether elements with the `display: none` property are
* removed from the DOM.
*/
private $isRemoveDisplayNoneEnabled = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the option name is a bit misleading. As it is about removing/keeping nodes that are display: none (and not about removing/keeping the display: none itself), I propose the name "shouldKeepInvisibleNodes". What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds fine.

@timothyasp timothyasp force-pushed the add-remove-display-none-as-option branch 3 times, most recently from cf1a367 to 5dd7e05 Compare May 19, 2015 00:32
@timothyasp
Copy link
Contributor Author

@oliverklee I think i've made all the requested changes. Thanks for the feedback!

@@ -338,6 +331,16 @@ public function disableStyleBlocksParsing()
}

/**
* Disables the removal of elements with `display: none` properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the period at the end of the sentence.

@oliverklee
Copy link
Contributor

Could you also please write a short documentation for this new feature for the README?

@timothyasp timothyasp force-pushed the add-remove-display-none-as-option branch from 5dd7e05 to 569fdcd Compare May 27, 2015 12:40
@timothyasp
Copy link
Contributor Author

Made the requested changes. The test failure looks Github related? Travis couldn't connect to github. I'm not sure how to requeue the test - @oliverklee could you do that?

@oliverklee
Copy link
Contributor

I've run the tests on this branch locally (as long as Travis does not play along). On your branch, I get the following failure:

klee@gonzales:~/src/php/emogrifier$ vendor/bin/phpunit Tests/
PHPUnit 4.6.7 by Sebastian Bergmann and contributors.

...............................................................  63 / 155 ( 40%)
............................................................... 126 / 155 ( 81%)
...........................F.

Time: 74 ms, Memory: 5.00Mb

There was 1 failure:

1) Pelago\Tests\Unit\EmogrifierTest::emogrifyByDefaultRemovesElementsWithDisplayNoneInStyleAttribute
Failed asserting that '<!DOCTYPE html>
<html><body>
<div class="bar"></div>
<div class="foo"></div>
</body></html>
' contains "<div class="bar"></div><div class="foo"></div>".

/home/klee/src/php/emogrifier/Tests/Unit/EmogrifierTest.php:1130

FAILURES!
Tests: 155, Assertions: 155, Failures: 1.

Do the tests run fine on your local machine?

@oliverklee
Copy link
Contributor

And could you please prefix the commit message subject line with [FEATURE]?

$nodesWithStyleDisplayNone = $xpath->query(
'//*[contains(translate(translate(@style," ",""),"NOE","noe"),"display:none")]'
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line so that the guard clause is a single visible block.

This adds an options parameter and some tests for a `removeDisplayNone` option
which specifies if the Emogrifier parser will remove elements with the style
"display: none".

Unfortunatly, the nice little optimization has some consiquences.

When writing responsive email templates, "display: none" is used often to hide
certain sections of the template for desktop email clients and show them in
phone clients.

I can see how it'd be nice to clean up elements that will not be displayed in
some cases, so that's why I made it an options field.
@timothyasp timothyasp force-pushed the add-remove-display-none-as-option branch from 569fdcd to b32411f Compare May 27, 2015 19:33
@timothyasp
Copy link
Contributor Author

I address all your concerns - still looks like Travis isn't working with github.

@oliverklee
Copy link
Contributor

I've tested the PR locally, fixed the unit tests (the DIVs were not nested, which made the assertContains not find any potential problems reliably), merged locally, and pushed.

Thanks for contributing, @timothyasp! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants