Blame view

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