- Token name and options are now passed through parse() method
This commit is contained in:
1 parent
e9b2f0ece3
commit
b3a8e3aca2
29 files changed
+70
-59
No files matched your search
@@ -2,19 +2,26 @@
|
||||
|
||||
namespace Picea\ControlStructure;
|
||||
|
||||
enum PrintActionEnum : string {
|
||||
case prepend = "prepend";
|
||||
case default = "default";
|
||||
case append = "append";
|
||||
# case both = "both";
|
||||
}
|
||||
|
||||
class SectionToken implements ControlStructure {
|
||||
|
||||
public array $token = [ "section", "endsection" ];
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token)
|
||||
{
|
||||
$opt = $context->tokenOptions($token);
|
||||
protected PrintActionEnum $action = PrintActionEnum::default;
|
||||
|
||||
if (in_array('prepend', $opt)) {
|
||||
$context->sectionAction = "prepend";
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||
{
|
||||
if (in_array('prepend', $options)) {
|
||||
$this->action = PrintActionEnum::prepend;
|
||||
}
|
||||
elseif (in_array('append', $opt)) {
|
||||
$context->sectionAction = "append";
|
||||
elseif (in_array('append', $options)) {
|
||||
$this->action = PrintActionEnum::append;
|
||||
}
|
||||
|
||||
switch($token) {
|
||||
@@ -30,7 +37,7 @@ class SectionToken implements ControlStructure {
|
||||
}
|
||||
}
|
||||
|
||||
protected function printSection($context, ?string $arguments) : string
|
||||
protected function printSection($context, ? string $arguments) : string
|
||||
{
|
||||
list($name, $options) = array_pad(explode(',', $arguments, 2), 2, null);
|
||||
|
||||
@@ -47,9 +54,7 @@ class SectionToken implements ControlStructure {
|
||||
'options' => $options,
|
||||
];
|
||||
|
||||
$action = $options['action'] ?? $context->sectionAction ?? "default";
|
||||
|
||||
unset($context->sectionAction);
|
||||
$action = $options['action'] ?? $this->action->value;
|
||||
|
||||
if (! in_array($action, ['prepend', 'append', 'default'])) {
|
||||
throw new \RuntimeException("An unsupported action `$action` was given as an option of a {% section %} tag");
|
||||
|
||||
Reference in new issue
Block a user