mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
wrap up engine for setting properties on elements
This commit is contained in:
parent
2be39a4756
commit
5307569bba
@ -32,11 +32,14 @@ class PdfMaker
|
||||
|
||||
public function build()
|
||||
{
|
||||
// $raw = $this->design->html();
|
||||
|
||||
$this->updateElementProperties($this->data['template']);
|
||||
$this->updateVariables($this->data['variables']);
|
||||
if (isset($this->data['template'])) {
|
||||
$this->updateElementProperties($this->data['template']);
|
||||
}
|
||||
|
||||
if (isset($this->data['variables'])) {
|
||||
$this->updateVariables($this->data['variables']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -120,12 +120,18 @@ class PdfMakerTest extends TestCase
|
||||
['element' => 'thead', 'content' => '', 'elements' => [
|
||||
['element' => 'th', 'content' => 'Company',],
|
||||
['element' => 'th', 'content' => 'Contact'],
|
||||
['element' => 'th', 'content' => 'Country'],
|
||||
['element' => 'th', 'content' => 'Country', 'properties' => [
|
||||
'colspan' => 3,
|
||||
]],
|
||||
]],
|
||||
['element' => 'tr', 'content' => '', 'elements' => [
|
||||
['element' => 'td', 'content' => '$company'],
|
||||
['element' => 'td', 'content' => '$email'],
|
||||
['element' => 'td', 'content' => '$country'],
|
||||
['element' => 'td', 'content' => '$country', 'elements' => [
|
||||
['element' => 'a', 'content' => 'Click here for a link', 'properties' => [
|
||||
'href' => 'https://github.com/invoiceninja/invoiceninja',
|
||||
]],
|
||||
]],
|
||||
]],
|
||||
],
|
||||
],
|
||||
@ -133,7 +139,7 @@ class PdfMakerTest extends TestCase
|
||||
'variables' => [
|
||||
'$company' => 'Invoice Ninja',
|
||||
'$email' => 'contact@invoiceninja.com',
|
||||
'$country' => 'UK',
|
||||
'$country' => 'UK',
|
||||
],
|
||||
];
|
||||
|
||||
@ -143,8 +149,8 @@ class PdfMakerTest extends TestCase
|
||||
->design(Business::class)
|
||||
->build();
|
||||
|
||||
info($maker->getCompiledHTML());
|
||||
$compiled = 'contact@invoiceninja.com';
|
||||
|
||||
$this->assertTrue(true);
|
||||
$this->assertStringContainsString($compiled, $maker->getCompiledHTML());
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ trait PdfMakerUtilities
|
||||
|
||||
if (isset($element['properties'])) {
|
||||
foreach ($element['properties'] as $property => $value) {
|
||||
$this->updateElementProperty($element['id'], $property, $value);
|
||||
$this->updateElementProperty($node, $property, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,10 +51,8 @@ trait PdfMakerUtilities
|
||||
}
|
||||
}
|
||||
|
||||
public function updateElementProperty(string $element, string $attribute, string $value)
|
||||
public function updateElementProperty($element, string $attribute, string $value)
|
||||
{
|
||||
$element = $this->document->getElementById($element);
|
||||
|
||||
$element->setAttribute($attribute, $value);
|
||||
|
||||
if ($element->getAttribute($attribute) === $value) {
|
||||
@ -69,6 +67,12 @@ trait PdfMakerUtilities
|
||||
foreach ($children as $child) {
|
||||
$_child = $this->document->createElement($child['element'], $child['content']);
|
||||
$element->appendChild($_child);
|
||||
|
||||
if (isset($child['properties'])) {
|
||||
foreach ($child['properties'] as $property => $value) {
|
||||
$this->updateElementProperty($_child, $property, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($child['elements'])) {
|
||||
$this->createElementContent($_child, $child['elements']);
|
||||
|
@ -1,3 +1,4 @@
|
||||
<!-- Business -->
|
||||
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
|
||||
<div id="header">This is $title</div>
|
||||
<table id="product-table"></table>
|
Loading…
Reference in New Issue
Block a user