Get rid of double html parsing during render
[MAILPOET-1797]
This commit is contained in:
committed by
M. Shull
parent
59d960b42f
commit
66ae3edf78
@ -11,7 +11,6 @@ if (!defined('ABSPATH')) exit;
|
||||
class Renderer {
|
||||
public $blocks_renderer;
|
||||
public $columns_renderer;
|
||||
public $DOM_parser;
|
||||
public $CSS_inliner;
|
||||
public $newsletter;
|
||||
public $preview;
|
||||
@ -26,7 +25,6 @@ class Renderer {
|
||||
$this->preview = $preview;
|
||||
$this->blocks_renderer = new Blocks\Renderer($this->newsletter);
|
||||
$this->columns_renderer = new Columns\Renderer();
|
||||
$this->DOM_parser = new pQuery();
|
||||
$this->CSS_inliner = new \MailPoet\Util\CSS();
|
||||
$this->template = file_get_contents(dirname(__FILE__) . '/' . self::NEWSLETTER_TEMPLATE);
|
||||
$this->premium_activated = License::getLicense();
|
||||
@ -62,8 +60,8 @@ class Renderer {
|
||||
$newsletter['preheader'],
|
||||
$rendered_body
|
||||
));
|
||||
$template = $this->inlineCSSStyles($template);
|
||||
$template = $this->postProcessTemplate($template);
|
||||
$template_dom = $this->inlineCSSStyles($template);
|
||||
$template = $this->postProcessTemplate($template_dom);
|
||||
|
||||
$rendered_newsletter = array(
|
||||
'html' => $template,
|
||||
@ -150,8 +148,7 @@ class Renderer {
|
||||
return @\Html2Text\Html2Text::convert($template);
|
||||
}
|
||||
|
||||
private function postProcessTemplate($template) {
|
||||
$DOM = $this->DOM_parser->parseStr($template);
|
||||
private function postProcessTemplate($DOM) {
|
||||
// replace spaces in image tag URLs
|
||||
foreach ($DOM->query('img') as $image) {
|
||||
$image->src = str_replace(' ', '%20', $image->src);
|
||||
|
@ -35,7 +35,6 @@ class CSS {
|
||||
*/
|
||||
function inlineCSS($url, $contents=null) {
|
||||
$html = \pQuery::parseStr($contents);
|
||||
|
||||
if (!is_object($html)) {
|
||||
return false;
|
||||
}
|
||||
@ -124,7 +123,7 @@ class CSS {
|
||||
}
|
||||
|
||||
// Let simple_html_dom give us back our HTML with inline CSS!
|
||||
return (string)$html;
|
||||
return $html;
|
||||
}
|
||||
|
||||
function parseCSS($text) {
|
||||
|
@ -41,7 +41,7 @@ class CSSTest extends \MailPoetUnitTest {
|
||||
$styles = 'p { color: red; }';
|
||||
$content = '<p>Foo</p>';
|
||||
$html = $this->buildHtml($styles, $content);
|
||||
$result_html = $this->css->inlineCSS(null, $html);
|
||||
$result_html = (string)$this->css->inlineCSS(null, $html);
|
||||
$this->assertContains('<p style="color:red">', $result_html);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ class CSSTest extends \MailPoetUnitTest {
|
||||
$styles = 'p { color: red; } .blue { color: blue; }';
|
||||
$content = '<p class="blue">Foo</p>';
|
||||
$html = $this->buildHtml($styles, $content);
|
||||
$result_html = $this->css->inlineCSS(null, $html);
|
||||
$result_html = (string)$this->css->inlineCSS(null, $html);
|
||||
$this->assertContains('<p class="blue" style="color:blue">', $result_html);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class CSSTest extends \MailPoetUnitTest {
|
||||
$styles = 'p { color: red; }';
|
||||
$content = '<p style="color:green">Foo</p>';
|
||||
$html = $this->buildHtml($styles, $content);
|
||||
$result_html = $this->css->inlineCSS(null, $html);
|
||||
$result_html = (string)$this->css->inlineCSS(null, $html);
|
||||
$this->assertContains('<p style="color:green">', $result_html);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ class CSSTest extends \MailPoetUnitTest {
|
||||
$styles = 'p { color: red !important; }';
|
||||
$content = '<p style="color:green !important">Foo</p>';
|
||||
$html = $this->buildHtml($styles, $content);
|
||||
$result_html = $this->css->inlineCSS(null, $html);
|
||||
$result_html = (string)$this->css->inlineCSS(null, $html);
|
||||
$this->assertContains('<p style="color:red">', $result_html);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user