Merge pull request #39 from Mibew/unless_else

Add "else" block to "unless" helper
This commit is contained in:
Behrooz Shabani 2014-01-23 06:01:16 -08:00
commit 6e7f5459a3
2 changed files with 20 additions and 1 deletions

10
src/Handlebars/Helpers.php Executable file → Normal file
View File

@ -9,6 +9,7 @@
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @author Dmitriy Simushev <simushevds@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT>
@ -150,8 +151,15 @@ class Helpers
* @var $source string
*/
$tmp = $context->get($args);
$buffer = '';
if (!$tmp) {
$template->setStopToken('else');
$buffer = $template->render($context);
$template->setStopToken(false);
} else {
$template->setStopToken('else');
$template->discard();
$template->setStopToken(false);
$buffer = $template->render($context);
}

View File

@ -8,6 +8,7 @@
* @category Xamin
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Dmitriy Simushev <simushevds@gmail.com>
* @copyright 2013 (c) f0ruD A
* @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$
@ -172,6 +173,16 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
array('data' => false),
'ok'
),
array(
'{{#unless data}}ok{{else}}fail{{/unless}}',
array('data' => false),
'ok'
),
array(
'{{#unless data}}fail{{else}}ok{{/unless}}',
array('data' => true),
'ok'
),
array(
'{{#bindAttr data}}',
array(),