- Small refractoring of code, merge tokens
- Completed block token
This commit is contained in:
1 parent
bf3816c3db
commit
ce4ef6351a
21 files changed
+370
-194
No files matched your search
@@ -4,9 +4,24 @@ namespace Picea\ControlStructure;
|
||||
|
||||
class SectionToken implements ControlStructure {
|
||||
|
||||
public string $token = "section";
|
||||
public array $token = [ "section", "endsection" ];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||
switch($token) {
|
||||
case "section":
|
||||
return $this->printSection($context, $arguments);
|
||||
|
||||
case "endsection":
|
||||
if ( empty($context->sections) ) {
|
||||
throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag");
|
||||
}
|
||||
|
||||
return $this->printEndSection($context);
|
||||
}
|
||||
}
|
||||
|
||||
protected function printSection($context, ?string $arguments) : string
|
||||
{
|
||||
list($name, $options) = array_pad(explode(',', $arguments, 2), 2, null);
|
||||
|
||||
if ( $options ?? false ) {
|
||||
@@ -34,4 +49,11 @@ class SectionToken implements ControlStructure {
|
||||
\$___class__template->sectionList[$name]['$action'][] = [ 'order' => $order, 'callback' => function() use (\$picea, \$___class__template, \$___global_variables, \$___variables) {
|
||||
extract(\$___global_variables); extract(\$___variables, \EXTR_OVERWRITE); ?>";
|
||||
}
|
||||
}
|
||||
|
||||
protected function printEndSection($context) : string
|
||||
{
|
||||
$section = array_pop($context->sections);
|
||||
$build = $context->extendFrom ? "" : "\$___class__template->renderSection({$section['name']});";
|
||||
return "<?php }]; $build?>";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user