Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Temp code to troubleshoot travis
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed May 3, 2014
1 parent 692ce1c commit e8c922c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
57 changes: 33 additions & 24 deletions src/SurfStack/Templating/Template_Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,33 +756,44 @@ protected function getRequiredClasses($class)
//return '';
return join(PHP_EOL, array_reverse($arrRequire));
}

public $pre;
public $post;

/**
* Return the render() function so the compiled template can
* call the plugin
* @param array $matches
* Replace plugin tags with PHP code
* @param string $content
* @return string
*/
protected function callPluginDynamic(array $matches)
protected function parsePlugins($content)
{
$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));
$this->pre = true;
$this->post = false;

// Get the requires classes as strings
$require = $this->getRequiredClasses('\SurfStack\Templating\Plugin\\'.$pluginName);
// Load the plugin content and replace
return preg_replace_callback(array_values($this->loadPlugins()), function($matches) {
$pluginName = $matches[1];
$pluginData = $matches[2];
// Block has content, Slice does not
$pluginContent = (isset($matches[3]) ? "'".addslashes($matches[3])."'" : '');

return "<?php $require
\$class = new \SurfStack\Templating\Plugin\\$pluginName();
\$class->store('arrEngineVariables', \$this->variables);
\$class->store('arrEngineInternals', \$this->internal);
\$class->store('arrPluginVariables', $sPassed);
echo \$class->render($pluginContent); ?>";
}
// 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 "<?php $require
\$class = new \SurfStack\Templating\Plugin\\$pluginName();
\$class->store('arrEngineVariables', \$this->variables);
\$class->store('arrEngineInternals', \$this->internal);
\$class->store('arrPluginVariables', $sPassed);
echo \$class->render($pluginContent); ?>";
}, $content);
}

/**
* Replace custom tags with standard PHP tags
* @param string $content
Expand Down Expand Up @@ -840,10 +851,8 @@ protected function modifyTemplateRegex($content)
$regex = array_merge($regex, $custom);
$content = preg_replace(array_values($regex), array_keys($regex), $content);

// Load the plugin content
$arrPlugins = $this->loadPlugins();
return preg_replace_callback(array_values($arrPlugins), array($this, 'callPluginDynamic'), $content);
//return preg_replace_callback(array_values($arrPlugins), array($this, 'callPluginStatic'), $content);
// Replace the plugin tags
return $this->parsePlugins($content);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/SurfStack/Templating/Template_Engine_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ 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->pre);
$this->assertTrue($this->view->post);
}

public function testSlice()
{
$this->expectOutputString(date('Y'));
Expand Down

0 comments on commit e8c922c

Please sign in to comment.