- Added a new {% block ... %} token
- Added a new {% php ... %} token
- Fixed a bug with an OR if foreach is empty
This commit is contained in:
1 parent
0e201b77f2
commit
404d1f4359
9 files changed
+143
-22
No files matched your search
@@ -2,13 +2,35 @@
|
||||
|
||||
namespace Picea\Extension;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
|
||||
class JsonExtension implements Extension {
|
||||
|
||||
public string $token = "json";
|
||||
public array $token = [ "json", "json.pretty" ];
|
||||
|
||||
public int $flags = JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_THROW_ON_ERROR;
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||
return "<?php echo json_encode($arguments, {$this->flags}) ?>";
|
||||
public function __construct(? Context $context = null) {
|
||||
if ($context) {
|
||||
$this->register($context);
|
||||
}
|
||||
}
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||
|
||||
$flag = $this->flags;
|
||||
|
||||
if ( $token === "json.pretty" ) {
|
||||
$flag = \JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
return "<?php echo json_encode($arguments, $flag) ?>";
|
||||
}
|
||||
|
||||
public function register(Context $context) : void
|
||||
{
|
||||
$context->pushFunction("json", function($arguments, ? int $flags = null) {
|
||||
return json_encode($arguments, \JSON_FORCE_OBJECT);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Extension;
|
||||
|
||||
class PhpExtension implements Extension {
|
||||
|
||||
public array $token = [ "php" ];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||
return "<?php $arguments ?>";
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class UrlExtension implements Extension {
|
||||
|
||||
protected array $routes;
|
||||
|
||||
public array $tokens = [ "url" , "route", "asset" ];
|
||||
public array $tokens = [ "url" , "route", "asset", "url.parameters" ];
|
||||
|
||||
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
|
||||
$this->urlBase = trim($urlBase, "/");
|
||||
@@ -31,6 +31,9 @@ class UrlExtension implements Extension {
|
||||
|
||||
case "url":
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildUrl($arguments) ?>";
|
||||
|
||||
case "url.parameters":
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->setUrlParameters($arguments) ?>";
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -43,11 +46,16 @@ class UrlExtension implements Extension {
|
||||
$context->pushFunction("route", [ $this, 'buildRouteUrl' ]);
|
||||
}
|
||||
|
||||
public function buildUrl(string $uri = "", array $parameters = []) : string
|
||||
public function setUrlParameters(string $url = "", array $parameters = []) : string
|
||||
{
|
||||
return $this->url() . "/" . ltrim($uri, "/") . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
||||
return $url . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
||||
}
|
||||
|
||||
public function buildUrl(string $uri = "", array $parameters = []) : string
|
||||
{
|
||||
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $parameters);
|
||||
}
|
||||
|
||||
public function buildAssetUrl(string $uri, array $parameters = []) : string
|
||||
{
|
||||
return $this->buildUrl($uri, array_replace([ 'v' => $this->assetToken ], $parameters));
|
||||
|
||||
Reference in new issue
Block a user