Skip to content

Commit

Permalink
Merge pull request #145 from fenom-template/develop
Browse files Browse the repository at this point in the history
2.5.1
  • Loading branch information
bzick committed Feb 2, 2015
2 parents 1a72b9d + d541763 commit 5dc7bbf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Fenom/Template.php
Expand Up @@ -667,6 +667,10 @@ public function parseExpr(Tokenizer $tokens)
$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;
}
Expand Down Expand Up @@ -780,7 +784,7 @@ public function parseTerm(Tokenizer $tokens, &$is_var = false)
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)';
Expand Down
2 changes: 1 addition & 1 deletion src/Fenom/Tokenizer.php
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/cases/Fenom/TemplateTest.php
Expand Up @@ -106,6 +106,7 @@ public static function providerVars()
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 ::'),
);
}
Expand Down Expand Up @@ -657,6 +658,8 @@ public static function providerTernary()
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),
Expand Down

0 comments on commit 5dc7bbf

Please sign in to comment.