Skip to content

Commit

Permalink
snippet wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 1, 2023
1 parent 0729ede commit 02a7fc4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Application/UI/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function redrawControl(?string $snippet = null, bool $redraw = true): voi
$this->invalidSnippets = [];

} else {
$this->invalidSnippets[$snippet] = false;
unset($this->invalidSnippets[$snippet]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/Bridges/ApplicationLatte/Nodes/ControlNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ControlNode extends StatementNode
public ?ExpressionNode $method = null;
public ArrayNode $args;
public ?bool $escape = null;
public bool $inSnippetArea = false;


public static function create(Tag $tag): static
Expand All @@ -40,6 +41,7 @@ public static function create(Tag $tag): static
$stream = $tag->parser->stream;
$node = new static;
$node->name = $tag->parser->parseUnquotedStringOrExpression(colon: false);
$node->inSnippetArea = $tag->closestTag(['snippetArea']) && !$tag->closestTag(['snippet']);
if ($stream->tryConsume(':')) {
$node->method = $tag->parser->parseExpression();
}
Expand Down Expand Up @@ -94,11 +96,14 @@ public function print(PrintContext $context): string
$this->name,
);

$fetchCode .= $this->inSnippetArea
? 'if ($ʟ_tmp instanceof Nette\Application\UI\Renderable) $ʟ_tmp->snippetMode = $this->global->uiControl->snippetMode;'
: 'if ($ʟ_tmp instanceof Nette\Application\UI\Renderable) $ʟ_tmp->redrawControl(null, $ʟ_tmp->snippetMode = false);';

if ($this->escape) {
return $context->format(
<<<'XX'
%raw
if ($ʟ_tmp instanceof Nette\Application\UI\Renderable) $ʟ_tmp->redrawControl(null, false);
ob_start(fn() => '');
$ʟ_tmp->%raw(%args) %line;
$ʟ_fi = new LR\FilterInfo(%dump); echo %modifyContent(ob_get_clean());
Expand All @@ -117,7 +122,6 @@ public function print(PrintContext $context): string
return $context->format(
<<<'XX'
%raw
if ($ʟ_tmp instanceof Nette\Application\UI\Renderable) $ʟ_tmp->redrawControl(null, false);
$ʟ_tmp->%raw(%args) %line;


Expand Down
3 changes: 1 addition & 2 deletions src/Bridges/ApplicationLatte/SnippetRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public function renderSnippets(array $blocks, array $params): bool
}

$this->renderingSnippets = true;
$this->control->snippetMode = false;
foreach ($blocks as $name => $block) {
if (!$this->control->isControlInvalid($name)) {
continue;
Expand All @@ -117,7 +116,7 @@ public function renderSnippets(array $blocks, array $params): bool
$function($params);
}

$this->control->snippetMode = true;
$this->control->redrawControl(null, false);
$this->renderChildren();
return true;
}
Expand Down

0 comments on commit 02a7fc4

Please sign in to comment.