Engine for editing templates

This commit is contained in:
Benjamin Beganović 2020-09-08 13:21:07 +02:00
parent 2e66a4df83
commit 14dc3ea2aa
3 changed files with 24 additions and 2 deletions

View File

@ -173,7 +173,11 @@ class PreviewController extends BaseController
$html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice');
$design = new Design(strtolower(request()->design['name']));
if (isset(request()->design['name'])) {
$design = new Design(strtolower(request()->design['name']));
} else {
$design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]);
}
// $designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity));
// $html = $this->generateEntityHtml($designer, $entity_obj);
@ -193,7 +197,7 @@ class PreviewController extends BaseController
->design($design)
->build();
info($maker->getCompiledHTML(true));
// info($maker->getCompiledHTML(true));
$file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company());

View File

@ -45,6 +45,7 @@ class Design extends BaseDesign
const MODERN = 'modern';
const PLAIN = 'plain';
const PLAYFUL = 'playful';
const CUSTOM = 'custom';
public function __construct(string $design = null, array $options = [])
{
@ -55,6 +56,12 @@ class Design extends BaseDesign
public function html(): ?string
{
if ($this->design == 'custom.html') {
return $this->composeFromPartials(
$this->options['custom_partials']
);
}
$path = isset($this->options['custom_path'])
? $this->options['custom_path']
: config('ninja.designs.base_path');

View File

@ -186,4 +186,15 @@ trait DesignHelpers
return false;
}
public function composeFromPartials(array $partials)
{
$html = '';
$html .= $partials['header'];
$html .= $partials['body'];
$html .= $partials['footer'];
return $html;
}
}