Refactor email content styles from string to array
[MAILPOET-5591]
This commit is contained in:
@@ -42,17 +42,16 @@ class Renderer {
|
||||
$parser = new \WP_Block_Parser();
|
||||
$parsedBlocks = $parser->parse($post->post_content); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
|
||||
$parsedBlocks = $this->preprocessManager->preprocess($parsedBlocks, $this->stylesController->getEmailLayoutStyles());
|
||||
$layoutStyles = $this->stylesController->getEmailLayoutStyles();
|
||||
$parsedBlocks = $this->preprocessManager->preprocess($parsedBlocks, $layoutStyles);
|
||||
$renderedBody = $this->blocksRenderer->render($parsedBlocks);
|
||||
|
||||
$styles = (string)file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_STYLES_FILE);
|
||||
$styles .= $this->stylesController->getEmailContentStyles();
|
||||
$styles = apply_filters('mailpoet_email_renderer_styles', $styles, $post);
|
||||
|
||||
$template = (string)file_get_contents(dirname(__FILE__) . '/' . self::TEMPLATE_FILE);
|
||||
|
||||
// Apply layout styles
|
||||
$layoutStyles = $this->stylesController->getEmailLayoutStyles();
|
||||
$template = str_replace(
|
||||
['{{width}}', '{{background}}', '{{padding_top}}', '{{padding_right}}', '{{padding_bottom}}', '{{padding_left}}'],
|
||||
[$layoutStyles['width'], $layoutStyles['background'], $layoutStyles['padding']['top'], $layoutStyles['padding']['right'], $layoutStyles['padding']['bottom'], $layoutStyles['padding']['left']],
|
||||
|
@@ -25,20 +25,46 @@ class StylesController {
|
||||
* Default styles applied to the email. These are going to be replaced by style settings.
|
||||
* This is currently more af a proof of concept that we can apply styles to the email.
|
||||
* We will gradually replace these hardcoded values with styles saved as global styles or styles saved with the email.
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
const DEFAULT_EMAIL_CONTENT_STYLES = "
|
||||
body { font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; }
|
||||
p { font-size: 16px; }
|
||||
h1 { font-size: 32px; }
|
||||
h2 { font-size: 24px; }
|
||||
h3 { font-size: 18px; }
|
||||
h4 { font-size: 16px; }
|
||||
h5 { font-size: 14px; }
|
||||
h6 { font-size: 12px; }
|
||||
";
|
||||
const DEFAULT_EMAIL_CONTENT_STYLES = [
|
||||
'typography' => [
|
||||
'fontFamily' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
||||
'fontSize' => '16px',
|
||||
],
|
||||
'h1' => [
|
||||
'typography' => [
|
||||
'fontSize' => '32px',
|
||||
],
|
||||
],
|
||||
'h2' => [
|
||||
'typography' => [
|
||||
'fontSize' => '24px',
|
||||
],
|
||||
],
|
||||
'h3' => [
|
||||
'typography' => [
|
||||
'fontSize' => '18px',
|
||||
],
|
||||
],
|
||||
'h4' => [
|
||||
'typography' => [
|
||||
'fontSize' => '16px',
|
||||
],
|
||||
],
|
||||
'h5' => [
|
||||
'typography' => [
|
||||
'fontSize' => '14px',
|
||||
],
|
||||
],
|
||||
'h6' => [
|
||||
'typography' => [
|
||||
'fontSize' => '12px',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function getEmailContentStyles(): string {
|
||||
public function getEmailContentStyles(): array {
|
||||
return self::DEFAULT_EMAIL_CONTENT_STYLES;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user