Changed Module.php to pass existing tests
authorJannis Grimm <jannis@gje.ch>
Mon, 25 Jul 2011 20:12:48 +0000 (22:12 +0200)
committerJannis Grimm <jannis@gje.ch>
Mon, 25 Jul 2011 20:12:48 +0000 (22:12 +0200)
lib/Twig/Node/Module.php

index 5d319e6..7079227 100644 (file)
@@ -72,7 +72,13 @@ class Twig_Node_Module extends Twig_Node
             ->write("\$parent = ")
             ->subcompile($this->getNode('parent'))
             ->raw(";\n")
-            ->write("if(!isset(\$this->parent[\$parent])) {\n")
+            ->write("if (\$parent instanceof Twig_Template) {\n")
+            ->indent()
+            ->write("\$name = \$parent->getTemplateName();\n")
+            ->write("\$this->parent[\$name] = \$parent;\n")
+            ->write("\$parent = \$name;\n")
+            ->outdent()
+            ->write("} elseif (!isset(\$this->parent[\$parent])) {\n")
             ->indent()
             ->write("\$this->parent[\$parent] = \$this->env->loadTemplate(\$parent);\n")
             ->outdent()
@@ -126,6 +132,7 @@ class Twig_Node_Module extends Twig_Node
             ->write("public function __construct(Twig_Environment \$env)\n", "{\n")
             ->indent()
             ->write("parent::__construct(\$env);\n\n")
+               ->write("\$this->parent = array();\n")
         ;
 
         $countTraits = count($this->getNode('traits'));
@@ -160,7 +167,6 @@ class Twig_Node_Module extends Twig_Node
             }
 
             $compiler
-                ->write("\$parent = array()")
                 ->write("\$this->blocks = array_replace(\n")
                 ->indent()
             ;