Files
piratepoet/lib/Newsletter/Renderer/Blocks/Renderer.php
Vlad 2793e74858 - Rewrites the rendering engine
- Updates tests
Closes #280
2016-01-07 17:24:32 -05:00

26 lines
871 B
PHP

<?php
namespace MailPoet\Newsletter\Renderer\Blocks;
class Renderer {
function render($data, $columnCount) {
array_map(function ($block) use (&$blockContent, &$columns, $columnCount) {
$blockContent .= $this->createElementFromBlockType($block, $columnCount);
if(isset($block['blocks'])) {
$blockContent = $this->render($block, $columnCount);
}
// vertical orientation denotes column container
if($block['type'] === 'container' && $block['orientation'] === 'vertical') {
$columns[] = $blockContent;
}
}, $data['blocks']);
return (isset($columns)) ? $columns : $blockContent;
}
function createElementFromBlockType($block, $columnCount) {
$blockClass = __NAMESPACE__ . '\\' . ucfirst($block['type']);
return (class_exists($blockClass)) ? $blockClass::render($block, $columnCount) : '';
}
}