-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version for Laravel 9 - 10, Latte 3.0
- Loading branch information
1 parent
f2ff77b
commit e290281
Showing
14 changed files
with
437 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Miko\LaravelLatte; | ||
|
||
use Latte\Extension as LatteExtension; | ||
|
||
class Extension extends LatteExtension | ||
{ | ||
public function getTags(): array | ||
{ | ||
return [ | ||
'n:href' => [Nodes\LinkNode::class, 'create'], | ||
'link' => [Nodes\LinkNode::class, 'create'], | ||
'n:src' => [Nodes\AssetNode::class, 'create'], | ||
'asset' => [Nodes\AssetNode::class, 'create'], | ||
'csrf' => [Nodes\CsrfNode::class, 'create'], | ||
'method' => [Nodes\MethodNode::class, 'create'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Miko\LaravelLatte\Nodes; | ||
|
||
use Latte\Compiler\Nodes\Php\Expression\ArrayNode; | ||
use Latte\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\ModifierNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
class AssetNode extends StatementNode | ||
{ | ||
public ExpressionNode $destination; | ||
public ArrayNode $args; | ||
public ModifierNode $modifier; | ||
public string $mode; | ||
|
||
|
||
public static function create(Tag $tag): ?static | ||
{ | ||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
$tag->expectArguments(); | ||
$node = new static(); | ||
$node->destination = $tag->parser->parseUnquotedStringOrExpression(); | ||
$tag->parser->stream->tryConsume(','); | ||
$node->args = $tag->parser->parseArguments(); | ||
$node->modifier = $tag->parser->parseModifier(); | ||
$node->modifier->escape = true; | ||
$node->modifier->check = false; | ||
$node->mode = $tag->name; | ||
|
||
if ($tag->isNAttribute()) { | ||
// move at the beginning | ||
array_unshift($tag->htmlElement->attributes->children, $node); | ||
return null; | ||
} | ||
|
||
return $node; | ||
} | ||
|
||
public function print(PrintContext $context): string | ||
{ | ||
if ($this->mode === 'src') { | ||
$context->beginEscape()->enterHtmlAttribute(null, '"'); | ||
$res = $context->format( | ||
<<<'XX' | ||
echo ' src="'; echo %modify(\Miko\LaravelLatte\Runtime\Asset::generate(%node)); echo '"'; | ||
XX, | ||
$this->modifier, | ||
$this->destination, | ||
$this->args, | ||
$this->position, | ||
); | ||
$context->restoreEscape(); | ||
return $res; | ||
} | ||
|
||
return $context->format( | ||
'echo %modify(\Miko\LaravelLatte\Runtime\Asset::generate(%node));', | ||
$this->modifier, | ||
$this->destination, | ||
$this->args, | ||
$this->position, | ||
); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->destination; | ||
yield $this->args; | ||
yield $this->modifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Miko\LaravelLatte\Nodes; | ||
|
||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
class CsrfNode extends StatementNode | ||
{ | ||
public static function create(Tag $tag): ?static | ||
{ | ||
$node = $tag->node = new self(); | ||
return $node; | ||
} | ||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format('echo csrf_field();'); | ||
} | ||
|
||
public function &getIterator(): \Generator | ||
{ | ||
if (false) { | ||
yield; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Miko\LaravelLatte\Nodes; | ||
|
||
use Latte\Compiler\Nodes\Php\Expression\ArrayNode; | ||
use Latte\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\ModifierNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
class LinkNode extends StatementNode | ||
{ | ||
public ExpressionNode $destination; | ||
public ArrayNode $args; | ||
public ModifierNode $modifier; | ||
public string $mode; | ||
|
||
|
||
public static function create(Tag $tag): ?static | ||
{ | ||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
$tag->expectArguments(); | ||
$node = new static(); | ||
$node->destination = $tag->parser->parseUnquotedStringOrExpression(); | ||
$tag->parser->stream->tryConsume(','); | ||
$node->args = $tag->parser->parseArguments(); | ||
$node->modifier = $tag->parser->parseModifier(); | ||
$node->modifier->escape = true; | ||
$node->modifier->check = false; | ||
$node->mode = $tag->name; | ||
|
||
if ($tag->isNAttribute()) { | ||
// move at the beginning | ||
array_unshift($tag->htmlElement->attributes->children, $node); | ||
return null; | ||
} | ||
|
||
return $node; | ||
} | ||
|
||
public function print(PrintContext $context): string | ||
{ | ||
if ($this->mode === 'href') { | ||
$context->beginEscape()->enterHtmlAttribute(null, '"'); | ||
$res = $context->format( | ||
<<<'XX' | ||
echo ' href="'; echo %modify(\Miko\LaravelLatte\Runtime\Link::generate(%node, %node?)) %line; echo '"'; | ||
XX, | ||
$this->modifier, | ||
$this->destination, | ||
$this->args, | ||
$this->position, | ||
); | ||
$context->restoreEscape(); | ||
return $res; | ||
} | ||
|
||
return $context->format( | ||
'echo %modify(\Miko\LaravelLatte\Runtime\Link::generate(%node, %node?)) %line;', | ||
$this->modifier, | ||
$this->destination, | ||
$this->args, | ||
$this->position, | ||
); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->destination; | ||
yield $this->args; | ||
yield $this->modifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Miko\LaravelLatte\Nodes; | ||
|
||
use Latte\Compiler\Nodes\Php\Expression\ArrayNode; | ||
use Latte\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
class MethodNode extends StatementNode | ||
{ | ||
private ExpressionNode $method; | ||
|
||
public static function create(Tag $tag): ?static | ||
{ | ||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
$tag->expectArguments(); | ||
$node = $tag->node = new self(); | ||
$node->method = $tag->parser->parseUnquotedStringOrExpression(); | ||
return $node; | ||
} | ||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format( | ||
<<<'XX' | ||
$ʟ__method = %node %line; | ||
Miko\LaravelLatte\Runtime\Method::validateArgument($ʟ__method); | ||
echo method_field($ʟ__method); | ||
XX, | ||
$this->method, | ||
$this->position, | ||
); | ||
} | ||
|
||
public function &getIterator(): \Generator | ||
{ | ||
if (false) { | ||
yield; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.