Merge pull request #145 from fenom-template/develop

2.5.1
This commit is contained in:
Ivan Shalganov 2015-02-02 12:11:30 +03:00
commit 5dc7bbfd56
3 changed files with 9 additions and 2 deletions

View File

@ -667,6 +667,10 @@ class Template extends Render
$var = false;
}
if ($tokens->is('?', '!')) {
if($cond) {
$term = array_pop($exp) . ' ' . $term;
$term = '('. array_pop($exp) . ' ' . $term . ')';
}
$term = $this->parseTernary($tokens, $term, $var);
$var = false;
}
@ -780,7 +784,7 @@ class Template extends Render
if ($this->_options & Fenom::DENY_METHODS) {
throw new \LogicException("Forbidden to call methods");
}
return $this->parseChain($tokens, $code);
return $unary . $this->parseChain($tokens, $code);
} elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) {
if($this->_options & Fenom::FORCE_VERIFY) {
return $unary . '(isset(' . $code . ') ? ' . $code . $tokens->getAndNext() . ' : null)';

View File

@ -83,7 +83,7 @@ class Tokenizer
public static $macros = array(
self::MACRO_STRING => array(
\T_ABSTRACT => 1, \T_ARRAY => 1, \T_AS => 1, \T_BREAK => 1,
\T_BREAK => 1, \T_CASE => 1, \T_CATCH => 1, \T_CLASS => 1,
\T_CASE => 1, \T_CATCH => 1, \T_CLASS => 1,
\T_CLASS_C => 1, \T_CLONE => 1, \T_CONST => 1, \T_CONTINUE => 1,
\T_DECLARE => 1, \T_DEFAULT => 1, \T_DIR => 1, \T_DO => 1,
\T_ECHO => 1, \T_ELSE => 1, \T_ELSEIF => 1, \T_EMPTY => 1,

View File

@ -106,6 +106,7 @@ class TemplateTest extends TestCase
array('hello, {"World"}!', $a, 'hello, World!'),
array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'),
array('hello, {$world->chunk(1)->self->chunk("new")}!', $b, 'hello, world!'),
array('hello, {!$world->chunk(1)->self->chunk("new")}!', $b, 'hello, !'),
array(':: {Fenom\Helper::method()->page->title} ::', $b, ':: test page ::'),
);
}
@ -657,6 +658,8 @@ class TemplateTest extends TestCase
array('{0 ? "no way" : "right"}', $a),
array('{$a ? "right" : "no way"}', $a),
array('{1 ? "right" : "no way"}', $a),
array('{$a == 1 ? "right" : "no way"}', $a),
array('{$a > 0 ? "right" : "no way"}', $a),
// !
array('{if $a!} right {/if}', $a),
array('{if 1!} right {/if}', $a),