Example #1
0
 public function on_partial($name, $indentation)
 {
     $ctx = $this->proust->getContext();
     if ($this->compileClass) {
         // use echo here because we already handled indentation in the partial itself
         $str = "\$ctx->pushPartial('{$name}', '{$indentation}');\n" . "echo (\$this->" . self::functionName($name) . "());\n" . "\$ctx->popPartial('{$name}');\n" . "/* end partial include {$name} */\n";
     } else {
         $str = $this->outputFunction . "(\$ctx->partial('{$name}', '{$indentation}'));\n";
     }
     $m = $this->proust;
     if (!$this->includeDynamicPartials && !$m->isPartialStatic($name)) {
         $this->pushLine($str);
         return;
     }
     if (!$this->includePartialCode) {
         if ($this->compileClass) {
             /* add partial to be compiled */
             $code = $m->getPartial($name);
             array_push($this->methodsToCompile, array($name, $code));
         }
         $this->pushLine($str);
         return;
     } else {
         $ctx = $m->getContext();
         if ($ctx->isPartialRecursion($name)) {
             if ($this->compileClass) {
                 /* add partial to be compiled */
                 $code = $m->getPartial($name);
                 array_push($this->methodsToCompile, array($name, $code));
             }
             /* revert to normal partial call. */
             $this->pushLine($str);
             return;
         }
         $ctx->pushPartial($name, $indentation);
         $code = $m->getPartial($name);
         $c = new Generator($this->options);
         $res = $c->compileCode($code, array("type" => "raw"));
         $ctx->popPartial($name);
         $str = "/* partial included code {$name} */\n" . "\$ctx->pushPartial('{$name}', '{$indentation}');\n" . $res . "\n" . "\$ctx->popPartial('{$name}');\n" . "/* end partial include {$name} */\n";
         $this->pushLine($str);
     }
 }
Example #2
0
 public function compile($code, $context = null, $options = array())
 {
     $name = $this->getCodeCacheKey($code, $context);
     if (array_key_exists($name, $this->phpCache)) {
         return $this->phpCache[$name];
     }
     $compilerOptions = $this->compilerOptions;
     $compilerOptions["proust"] = $this;
     $options = array_merge(array("type" => "variable", "name" => "f"), $options);
     $generator = new Generator($compilerOptions);
     $php = $generator->compileCode($code, $options);
     $this->phpCache[$name] = $php;
     return $php;
 }