- 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:
Dave Mc Nicoll committed 2020-03-30 12:13:02 -04:00
1 parent 0e201b77f2
commit 404d1f4359
9 files changed
+143 -22

No files matched your search

+25 -3
View File
@@ -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);
});
}
}