Example #1
0
 public function compile(CompilerInterface $compiler)
 {
     // Render the head of the extended template
     $compiler->head('<?=$tpl->renderHead( ');
     foreach ($this->getAttributes() as $a) {
         $subcompiler = new Compiler($a);
         $compiler->head($subcompiler->compile());
     }
     $compiler->head(')?>');
     // Write the head of the current template
     foreach ($this->getChildren() as $c) {
         $subcompiler = new Compiler($c);
         $subcompiler->compile();
         $compiler->head($subcompiler->getHead());
     }
     // Render the body of the extended template
     $compiler->write('<?=$tpl->renderBody( ');
     foreach ($this->getAttributes() as $a) {
         $subcompiler = new Compiler($a);
         $compiler->write($subcompiler->compile());
     }
     $compiler->write(')?>');
 }
Example #2
0
 public function compile(CompilerInterface $compiler)
 {
     $nameAttr = $this->getAttribute(0);
     $subcompiler = new Compiler($nameAttr);
     $name = $subcompiler->compile();
     // Determine which function to use
     $blockHeadFunction = 'setBlock';
     if ($this->getAttribute(1)) {
         $optionAttr = $this->getAttribute(1);
         if ($optionAttr->getValue() === 'prepend') {
             $blockHeadFunction = 'prependBlock';
         } elseif ($optionAttr->getValue() === 'append') {
             $blockHeadFunction = 'appendBlock';
         }
     }
     // Write the heads of the children first
     foreach ($this->getChildren() as $c) {
         $subcompiler = new Compiler($c);
         $subcompiler->compile();
         $compiler->head($subcompiler->getHead());
     }
     // Write head of itself
     $compiler->head('<?php $env->' . $blockHeadFunction . '( ');
     $compiler->head($name);
     $compiler->head(', function() use ( $env, $tpl ) { ?>');
     foreach ($this->getChildren() as $c) {
         $subcompiler = new Compiler($c);
         $subcompiler->compile();
         $compiler->head($subcompiler->getBody());
     }
     $compiler->head('<?php } ); ?>');
     // Render itself
     $compiler->write('<?php $env->getBlock( ');
     $compiler->write($name);
     $compiler->write('); ?>');
 }
Example #3
0
 public function testCompileShouldReturnEmptyString()
 {
     $compiler = new Compiler(new RootNode());
     $this->assertEquals('', $compiler->compile());
 }