diff --git a/src/SurfStack/Templating/Template_Engine.php b/src/SurfStack/Templating/Template_Engine.php index 503d35b..247c3b8 100644 --- a/src/SurfStack/Templating/Template_Engine.php +++ b/src/SurfStack/Templating/Template_Engine.php @@ -758,9 +758,32 @@ protected function getRequiredClasses($class) //return ''; return join(PHP_EOL, array_reverse($arrRequire)); } - - public $post; - public $plugrex; + + /** + * Replace the plugin tags with PHP code + * @param array $matches + * @return string + */ + protected function dynamicPluginReplacement($matches) + { + $pluginName = $matches[1]; + $pluginData = $matches[2]; + // Block has content, Slice does not + $pluginContent = (isset($matches[3]) ? "'".addslashes($matches[3])."'" : ''); + + // Get the variables as a renderable array + $sPassed = $this->buildRenderableArray($this->parsePluginVariables($pluginData)); + + // Get the requires classes as strings + $require = $this->getRequiredClasses('\SurfStack\Templating\Plugin\\'.$pluginName); + +return "store('arrEngineVariables', \$this->variables); +\$class->store('arrEngineInternals', \$this->internal); +\$class->store('arrPluginVariables', $sPassed); +echo \$class->render($pluginContent); ?>"; + } /** * Replace plugin tags with PHP code @@ -768,34 +791,9 @@ protected function getRequiredClasses($class) * @return string */ protected function parsePlugins($content) - { - $this->post = false; - - //$this->plugrex = array_values($this->loadPlugins()); - $this->plugrex = $this->loadPlugins(); - + { // Load the plugin content and replace - return preg_replace_callback(array_values($this->plugrex), function($matches) { - $pluginName = $matches[1]; - $pluginData = $matches[2]; - // Block has content, Slice does not - $pluginContent = (isset($matches[3]) ? "'".addslashes($matches[3])."'" : ''); - - // Get the variables as a renderable array - $sPassed = $this->buildRenderableArray($this->parsePluginVariables($pluginData)); - - // Get the requires classes as strings - $require = $this->getRequiredClasses('\SurfStack\Templating\Plugin\\'.$pluginName); - - $this->post = true; - - return "store('arrEngineVariables', \$this->variables); - \$class->store('arrEngineInternals', \$this->internal); - \$class->store('arrPluginVariables', $sPassed); - echo \$class->render($pluginContent); ?>"; - }, $content); + return preg_replace_callback(array_values($this->loadPlugins()), array($this, 'dynamicPluginReplacement') , $content); } /** diff --git a/tests/SurfStack/Templating/Template_Engine_Test.php b/tests/SurfStack/Templating/Template_Engine_Test.php index 947d2fd..6b5ab5c 100644 --- a/tests/SurfStack/Templating/Template_Engine_Test.php +++ b/tests/SurfStack/Templating/Template_Engine_Test.php @@ -340,49 +340,6 @@ public function testVariableBlock() $this->view->render(); } - public function testPrePost() - { - $this->view->clear(); - - $this->view->assign('test', 'Hello world'); - - $this->view->setTemplate('blockVariable.tpl'); - - $this->view->setLoadPlugins(true); - - $this->view->setStripTags(false); - - $this->view->setStripWhitespace(false); - - $this->render(); - - $this->assertTrue($this->view->post); - } - - public function testPlugRex() - { - $this->view->clear(); - - $this->view->assign('test', 'Hello world'); - - $this->view->setTemplate('blockVariable.tpl'); - - $this->view->setLoadPlugins(true); - - $this->view->setStripTags(false); - - $this->view->setStripWhitespace(false); - - $this->render(); - - $this->assertSame($this->view->plugrex, array( - 'Blank' => '/\{\s*(Blank)\s*(.*?)\}/i', - 'Bold' => '/\{\s*(Bold)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Bold\s*\}/i', - 'Passthru' => '/\{\s*(Passthru)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Passthru\s*\}/i', - 'Time' => '/\{\s*(Time)\s*(.*?)\}/i', - )); - } - public function testSlice() { $this->expectOutputString(date('Y'));