Skip to content

Commit

Permalink
Refactor Template and improve performance and type safety (#1349)
Browse files Browse the repository at this point in the history
* Refactor Template and improve performance and type safety

* DEBUG: parse 100% same incl. tags/index, but del/set rely on ref

* test - also not working

* DEBUG: use old/working Template

* Never delete, empty only

* WIP parallel templating to verify new Template

* FIX DIFF: it works, but "Content" should not be set set instead

* Fix parallel rendering for Grid/direct template usage

* fix CS

* do not set unneeded empty strings

* Revert "FIX DIFF: it works, but "Content" should not be set set instead"

This reverts commit 1caaa4d.

* Better fix: it works, but "Content" should not be set set instead

* Revert debug

* fix original typo

* fix tryDel with array

* Fix checkbox render properly
  • Loading branch information
mvorisek authored Jul 15, 2020
1 parent c07e8c4 commit badbfb9
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 527 deletions.
2 changes: 1 addition & 1 deletion docs/render.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Agile UI sometimes uses the following approach to render element on the outside:
1. Create new instance of $sub_view.
2. Set $sub_view->id = false;
3. Calls $view->_add($sub_view);
4. executes $sub_view->renderHTML()
4. executes $sub_view->renderHtml()

This returns a HTML that's stripped of any ID values, still linked to the main application but will not become part of the
render tree. This approach is useful when it's necessary to manipulate HTML and inject it directly into the template for
Expand Down
4 changes: 2 additions & 2 deletions docs/template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ under ``$template->template`::
// template property:
array (
0 => 'Hello ',
'subject#1' => array (
'subject#0' => array (
0 => 'world',
),
1 => '!!',
Expand All @@ -718,7 +718,7 @@ Property tags would contain::

array (
'subject'=> array( &array ),
'subject#1'=> array( &array )
'subject#0'=> array( &array )
)

As a result each tag will be stored under it's actual name and the name with
Expand Down
4 changes: 3 additions & 1 deletion src/Form/Control/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public function set($value = null, $junk = null)
*/
protected function renderView(): void
{
$this->template['label'] = $this->label ?: $this->caption;
if ($this->label) {
$this->template->set('Content', $this->label);
}

if ($this->field ? $this->field->get() : $this->content) {
$this->template->set('checked', 'checked');
Expand Down
7 changes: 1 addition & 6 deletions src/Form/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ protected function recursiveRender(): void
if ($element instanceof \atk4\ui\Form\Control\Checkbox) {
$template = $noLabelControl;
$element->template->set('Content', $label);
/*
$element->addClass('field');
$this->template->appendHtml('Fields', '<div class="field">'.$element->getHtml().'</div>');
continue;
*/
}

if ($this->label && $this->inline) {
Expand All @@ -204,7 +199,7 @@ protected function recursiveRender(): void
$element->placeholder = $label;
}

// Fields get extra pampering
// Controls get extra pampering
$template->setHtml('Input', $element->getHtml());
$template->trySet('label', $label);
$template->trySet('label_for', $element->id . '_input');
Expand Down
8 changes: 6 additions & 2 deletions src/GridLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ protected function buildTemplate()
$this->t_wrap->appendHtml('rows', '{/rows}');
$tmp = new Template($this->t_wrap->render());

$this->template->template['rows#1'] = $tmp->template['rows#1'];
// TODO replace later, the only use of direct template property access
$t = $this;
\Closure::bind(function () use ($t, $tmp) {
$t->template->template['rows#0'] = $tmp->template['rows#0'];
$t->template->rebuildTagsIndex();
}, null, Template::class)();

$this->template->rebuildTags();
$this->addClass($this->words[$this->columns] . ' column');
}
}
1 change: 1 addition & 0 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected function renderView(): void
if (!$this->icon && !$this->elements) {
$this->template->del('has_content');
$this->template->set('title', $this->content);
$this->content = false;
}

parent::renderView();
Expand Down
4 changes: 2 additions & 2 deletions src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Modal extends View
*/
public $contentCSS = ['img', 'content', 'atk-dialog-content'];

/*
/**
* if true, the <div class="actions"> at the bottom of the modal is
* shown. Automatically set to true if any actions are added
* shown. Automatically set to true if any actions are added.
*
* @var bool
*/
Expand Down
5 changes: 1 addition & 4 deletions src/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
/**
* Class implements ProgressBar.
*
* $bar = ProgressBar::addTo($app, [
* 10,
* 'label' => 'Processing files',
* ]);
* $bar = ProgressBar::addTo($app, [10, 'label' => 'Processing files']);
*/
class ProgressBar extends View
{
Expand Down
Loading

0 comments on commit badbfb9

Please sign in to comment.