-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-64085: [GitHub] Static versioning and styles minification bre…
…ak email fonts styles #8241
- Loading branch information
Showing
3 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
lib/internal/Magento/Framework/Css/PreProcessor/Adapter/CssInliner.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\Css\PreProcessor\Adapter; | ||
use Pelago\Emogrifier; | ||
|
||
class CssInliner | ||
{ | ||
/** | ||
* @var Emogrifier | ||
*/ | ||
private $emogrifier; | ||
|
||
/** | ||
* @param Emogrifier $emogrifier | ||
*/ | ||
public function __construct(Emogrifier $emogrifier) | ||
{ | ||
$this->emogrifier = $emogrifier; | ||
} | ||
|
||
/** | ||
* Sets the HTML to emogrify. | ||
* | ||
* @param string $html the HTML to emogrify, must be UTF-8-encoded | ||
* | ||
* @return void | ||
*/ | ||
public function setHtml($html) | ||
{ | ||
$this->emogrifier->setHtml($html); | ||
} | ||
|
||
/** | ||
* Sets the CSS to merge with the HTML. | ||
* | ||
* @param string $css the CSS to merge, must be UTF-8-encoded | ||
* | ||
* @return void | ||
*/ | ||
public function setCss($css) | ||
{ | ||
/** | ||
* Adds space to CSS string before passing to Emogrifier to fix known parsing issue with library. | ||
* https://github.com/jjriv/emogrifier/issues/370 | ||
*/ | ||
$cssWithAddedSpaces = preg_replace('#([\{\}>])#i', ' $1 ', $css); | ||
|
||
$this->emogrifier->setCss($cssWithAddedSpaces); | ||
} | ||
|
||
/** | ||
* Disables the parsing of <style> blocks. | ||
* | ||
* @return void | ||
*/ | ||
public function disableStyleBlocksParsing() | ||
{ | ||
$this->emogrifier->disableStyleBlocksParsing(); | ||
} | ||
|
||
/** | ||
* Applies $this->css to $this->html and returns the HTML with the CSS | ||
* applied. | ||
* | ||
* This method places the CSS inline. | ||
* | ||
* @return string | ||
* | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function process() | ||
{ | ||
return $this->emogrifier->emogrify(); | ||
} | ||
|
||
} |