| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of Mustache.php. |
| 5 |
* |
| 6 |
* (c) 2010-2014 Justin Hileman |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Mustache Lambda Helper. |
| 14 |
* |
| 15 |
* Passed as the second argument to section lambdas (higher order sections), |
| 16 |
* giving them access to a `render` method for rendering a string with the |
| 17 |
* current context. |
| 18 |
*/ |
| 19 |
class Mustache_LambdaHelper |
| 20 |
{ |
| 21 |
private $mustache; |
| 22 |
private $context; |
| 23 |
|
| 24 |
/** |
| 25 |
* Mustache Lambda Helper constructor. |
| 26 |
* |
| 27 |
* @param Mustache_Engine $mustache Mustache engine instance. |
| 28 |
* @param Mustache_Context $context Rendering context. |
| 29 |
*/ |
| 30 |
public function __construct(Mustache_Engine $mustache, Mustache_Context $context) |
| 31 |
{ |
| 32 |
$this->mustache = $mustache; |
| 33 |
$this->context = $context; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Render a string as a Mustache template with the current rendering context. |
| 38 |
* |
| 39 |
* @param string $string |
| 40 |
* |
| 41 |
* @return string Rendered template. |
| 42 |
*/ |
| 43 |
public function render($string) |
| 44 |
{ |
| 45 |
return $this->mustache |
| 46 |
->loadLambda((string) $string) |
| 47 |
->renderInternal($this->context); |
| 48 |
} |
| 49 |
} |
| 50 |
|