| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | /* |
| 4 | 4 | * This file is part of Mustache.php. |
| 5 | 5 | * |
| 6 | - * (c) 2012 Justin Hileman | |
| 6 | + * (c) 2010-2017 Justin Hileman | |
| 7 | 7 | * |
| 8 | 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | 9 | * file that was distributed with this source code. |
| 10 | 10 | */ |
| @@ -19,19 +19,22 @@ | ||
| 19 | 19 | class Mustache_LambdaHelper |
| 20 | 20 | { |
| 21 | 21 | private $mustache; |
| 22 | 22 | private $context; |
| 23 | + private $delims; | |
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * Mustache Lambda Helper constructor. |
| 26 | 27 | * |
| 27 | - * @param Mustache_Engine $mustache Mustache engine instance. | |
| 28 | - * @param Mustache_Context $context Rendering context. | |
| 28 | + * @param Mustache_Engine $mustache Mustache engine instance | |
| 29 | + * @param Mustache_Context $context Rendering context | |
| 30 | + * @param string $delims Optional custom delimiters, in the format `{{= <% %> =}}`. (default: null) | |
| 29 | 31 | */ |
| 30 | - public function __construct(Mustache_Engine $mustache, Mustache_Context $context) | |
| 32 | + public function __construct(Mustache_Engine $mustache, Mustache_Context $context, $delims = null) | |
| 31 | 33 | { |
| 32 | 34 | $this->mustache = $mustache; |
| 33 | 35 | $this->context = $context; |
| 36 | + $this->delims = $delims; | |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | 39 | /** |
| 37 | 40 | * Render a string as a Mustache template with the current rendering context. |
| @@ -37,13 +40,37 @@ | ||
| 37 | 40 | * Render a string as a Mustache template with the current rendering context. |
| 38 | 41 | * |
| 39 | 42 | * @param string $string |
| 40 | 43 | * |
| 41 | - * @return Rendered template. | |
| 44 | + * @return string Rendered template | |
| 42 | 45 | */ |
| 43 | 46 | public function render($string) |
| 44 | 47 | { |
| 45 | 48 | return $this->mustache |
| 46 | - ->loadLambda((string) $string) | |
| 49 | + ->loadLambda((string) $string, $this->delims) | |
| 47 | 50 | ->renderInternal($this->context); |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Render a string as a Mustache template with the current rendering context. | |
| 55 | + * | |
| 56 | + * @param string $string | |
| 57 | + * | |
| 58 | + * @return string Rendered template | |
| 59 | + */ | |
| 60 | + public function __invoke($string) | |
| 61 | + { | |
| 62 | + return $this->render($string); | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Get a Lambda Helper with custom delimiters. | |
| 67 | + * | |
| 68 | + * @param string $delims Custom delimiters, in the format `{{= <% %> =}}` | |
| 69 | + * | |
| 70 | + * @return Mustache_LambdaHelper | |
| 71 | + */ | |
| 72 | + public function withDelimiters($delims) | |
| 73 | + { | |
| 74 | + return new self($this->mustache, $this->context, $delims); | |
| 48 | 75 | } |
| 49 | 76 | } |