Merge pull request #133 from bzick/develop

Fix #132
This commit is contained in:
Ivan Shalganov 2015-01-08 16:06:52 +03:00
commit 47cee02dd3
5 changed files with 18 additions and 15 deletions

View File

@ -922,9 +922,9 @@ class Fenom
{ {
$options |= $this->_options; $options |= $this->_options;
if (is_array($template)) { if (is_array($template)) {
$key = dechex($options) . "@" . implode(",", $template); $key = $options . "@" . implode(",", $template);
} else { } else {
$key = dechex($options) . "@" . $template; $key = $options . "@" . $template;
} }
if (isset($this->_storage[$key])) { if (isset($this->_storage[$key])) {
/** @var Fenom\Template $tpl */ /** @var Fenom\Template $tpl */
@ -948,6 +948,10 @@ class Fenom
*/ */
public function templateExists($template) public function templateExists($template)
{ {
$key = $this->_options . "@" . $template;
if (isset($this->_storage[$key])) { // already loaded
return true;
}
if ($provider = strstr($template, ":", true)) { if ($provider = strstr($template, ":", true)) {
if (isset($this->_providers[$provider])) { if (isset($this->_providers[$provider])) {
return $this->_providers[$provider]->templateExists(substr($template, strlen($provider) + 1)); return $this->_providers[$provider]->templateExists(substr($template, strlen($provider) + 1));
@ -972,6 +976,7 @@ class Fenom
$fenom = $this; // used in template $fenom = $this; // used in template
$_tpl = include($this->_compile_dir . "/" . $file_name); $_tpl = include($this->_compile_dir . "/" . $file_name);
/* @var Fenom\Render $_tpl */ /* @var Fenom\Render $_tpl */
if (!($this->_options & self::AUTO_RELOAD) || ($this->_options & self::AUTO_RELOAD) && $_tpl->isValid()) { if (!($this->_options & self::AUTO_RELOAD) || ($this->_options & self::AUTO_RELOAD) && $_tpl->isValid()) {
return $_tpl; return $_tpl;
} }

View File

@ -107,11 +107,9 @@ class Modifier
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) { if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
if (count($match) == 3) { if (count($match) == 3) {
if ($by_words) { if ($by_words) {
return preg_replace('#\s.*$#usS', "", $match[1]) . $etc . preg_replace( return preg_replace('#\s.*$#usS', "", $match[1]) .
'#.*\s#usS', $etc .
"", preg_replace('#.*\s#usS', "", $match[2]);
$match[2]
);
} else { } else {
return $match[1] . $etc . $match[2]; return $match[1] . $etc . $match[2];
} }

View File

@ -146,8 +146,8 @@ class Provider implements ProviderInterface
*/ */
protected function _getTemplatePath($tpl) protected function _getTemplatePath($tpl)
{ {
$path = realpath($this->_path . "/" . $tpl);
if (($path = realpath($this->_path . "/" . $tpl)) && strpos($path, $this->_path) === 0) { if ($path && strpos($path, $this->_path) === 0) {
return $path; return $path;
} else { } else {
throw new \RuntimeException("Template $tpl not found"); throw new \RuntimeException("Template $tpl not found");

View File

@ -265,10 +265,9 @@ class Template extends Render
foreach ($this->_stack as $scope) { foreach ($this->_stack as $scope) {
$_names[] = '{' . $scope->name . '} opened on line ' . $scope->line; $_names[] = '{' . $scope->name . '} opened on line ' . $scope->line;
} }
throw new CompileException("Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode( /* @var Tag $scope */
", ", $message = "Unclosed tag" . (count($_names) > 1 ? "s" : "") . ": " . implode(", ", $_names);
$_names throw new CompileException($message, 0, 1, $this->_name, $scope->line);
), 0, 1, $this->_name, $scope->line); // for PHPStorm: $scope already defined there!
} }
$this->_src = ""; // cleanup $this->_src = ""; // cleanup
if ($this->_post) { if ($this->_post) {
@ -467,7 +466,7 @@ class Template extends Render
*/ */
public function addDepend(Render $tpl) public function addDepend(Render $tpl)
{ {
$this->_depends[$tpl->getScm()][$tpl->getName()] = $tpl->getTime(); $this->_depends[$tpl->getScm()][$tpl->getBaseName()] = $tpl->getTime();
} }
/** /**

View File

@ -17,6 +17,7 @@ class CustomProviderTest extends TestCase
$this->assertTrue($this->fenom->templateExists('my:include.tpl')); $this->assertTrue($this->fenom->templateExists('my:include.tpl'));
$this->assertFalse($this->fenom->templateExists('my:include-none.tpl')); $this->assertFalse($this->fenom->templateExists('my:include-none.tpl'));
$this->assertRender("start: {include 'my:include.tpl'}", 'start: include template'); $this->assertRender("start: {include 'my:include.tpl'}", 'start: include template');
//$this->assertRender("start: {import 'my:macros.tpl' as ops} {ops.add a=3 b=6}"); $this->assertTrue($this->fenom->getTemplate('my:include.tpl')->isValid());
} }
} }