Merge pull request #36 from cgray/master

Add support for .length on arrays
This commit is contained in:
Fzerorubigd 2014-01-20 01:16:19 -08:00
commit ab2d5adbb6
3 changed files with 14 additions and 2 deletions

View File

@ -9,7 +9,7 @@
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @author Chris Gray <chrisgray@gmail.com>
* @author Chris Gray <chris.w.gray@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @copyright 2013 (c) f0ruD A
@ -261,6 +261,8 @@ class Context
} elseif (is_array($variable)) {
if (isset($variable[$inside])) {
return $variable[$inside];
} elseif ($inside == "length") {
return count($variable);
}
} elseif (is_object($variable)) {
if (isset($variable->$inside)) {

View File

@ -9,7 +9,7 @@
* @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @author Chris Gray <chrisgray@gmail.com>
* @author Chris Gray <chris.w.gray@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT>

View File

@ -80,6 +80,16 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
array('data' => array('key' => 'result')),
'result'
),
array(
'{{data.length}}',
array("data" => array(1,2,3,4)),
'4'
),
array(
'{{data.length}}',
array("data"=> (object)array(1,2,3,4)),
''
)
);
}