-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added support for both Latte versions - `^2.5` and `^3.0` - added Latte extension `Latte\AssetExtension` - added tests for latte filters - updated PHPStan configuration - updated README
- Loading branch information
Showing
6 changed files
with
180 additions
and
33 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
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-nette/extension.neon | ||
- vendor/phpstan/phpstan-nette/rules.neon | ||
|
||
parameters: | ||
ignoreErrors: | ||
- | ||
message: '~If condition is always false\.~' | ||
path: src/DI/AssetExtension.php | ||
|
||
excludePaths: | ||
analyse: | ||
- src/Latte/AssetMacroSet.php |
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,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SixtyEightPublishers\Asset\Latte; | ||
|
||
use Latte\Extension; | ||
use Latte\Compiler\Tag; | ||
use Latte\Compiler\Node; | ||
use Latte\Compiler\PrintContext; | ||
use Symfony\Component\Asset\Packages; | ||
use Latte\Compiler\Nodes\AuxiliaryNode; | ||
|
||
final class AssetExtension extends Extension | ||
{ | ||
private Packages $packages; | ||
|
||
public function __construct(Packages $packages) | ||
{ | ||
$this->packages = $packages; | ||
} | ||
|
||
/** | ||
* @return array{asset: callable, asset_version: callable} | ||
*/ | ||
public function getTags(): array | ||
{ | ||
return [ | ||
'asset' => [$this, 'createAsset'], | ||
'asset_version' => [$this, 'createAssetVersion'], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array{asset: callable, asset_version: callable} | ||
*/ | ||
public function getFilters(): array | ||
{ | ||
return [ | ||
'asset' => [$this->packages, 'getUrl'], | ||
'asset_version' => [$this->packages, 'getVersion'], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array{symfonyPackages: Packages} | ||
*/ | ||
public function getProviders(): array | ||
{ | ||
return [ | ||
'symfonyPackages' => $this->packages, | ||
]; | ||
} | ||
|
||
public function createAsset(Tag $tag): Node | ||
{ | ||
$args = []; | ||
$path = $tag->parser->parseUnquotedStringOrExpression(); | ||
|
||
if (!$tag->parser->isEnd()) { | ||
$tag->parser->stream->tryConsume(','); | ||
$args = [$tag->parser->parseExpression()]; | ||
} | ||
|
||
return new AuxiliaryNode( | ||
fn (PrintContext $context) => $context->format( | ||
'echo %escape($this->global->symfonyPackages->getUrl(%node, %args));', | ||
$path, | ||
$args | ||
) | ||
); | ||
} | ||
|
||
public function createAssetVersion(Tag $tag): Node | ||
{ | ||
$args = []; | ||
$path = $tag->parser->parseUnquotedStringOrExpression(); | ||
|
||
if (!$tag->parser->isEnd()) { | ||
$tag->parser->stream->tryConsume(','); | ||
$args = [$tag->parser->parseExpression()]; | ||
} | ||
|
||
return new AuxiliaryNode( | ||
fn (PrintContext $context) => $context->format( | ||
'echo %escape($this->global->symfonyPackages->getVersion(%node, %args));', | ||
$path, | ||
$args | ||
) | ||
); | ||
} | ||
} |
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