@@ -50,6 +50,18 @@ class Mustache_LambdaHelper
|
|||||||
->renderInternal($this->context);
|
->renderInternal($this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a string as a Mustache template with the current rendering context.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
*
|
||||||
|
* @return string Rendered template
|
||||||
|
*/
|
||||||
|
public function __invoke($string)
|
||||||
|
{
|
||||||
|
return $this->render($string);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Lambda Helper with custom delimiters.
|
* Get a Lambda Helper with custom delimiters.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -49,4 +49,19 @@ class Mustache_Test_FiveThree_Functional_LambdaHelperTest extends PHPUnit_Framew
|
|||||||
|
|
||||||
$this->assertEquals('hello world!', $tpl->render($data));
|
$this->assertEquals('hello world!', $tpl->render($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLambdaHelperIsInvokable()
|
||||||
|
{
|
||||||
|
$one = $this->mustache->loadTemplate('{{name}}');
|
||||||
|
$two = $this->mustache->loadTemplate('{{#lambda}}{{name}}{{/lambda}}');
|
||||||
|
|
||||||
|
$foo = new StdClass();
|
||||||
|
$foo->name = 'Mario';
|
||||||
|
$foo->lambda = function ($text, $render) {
|
||||||
|
return strtoupper($render($text));
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->assertEquals('Mario', $one->render($foo));
|
||||||
|
$this->assertEquals('MARIO', $two->render($foo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user