[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/classes/output/ -> mustache_pix_helper.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Mustache helper render pix icons.
  19   *
  20   * @package    core
  21   * @category   output
  22   * @copyright  2015 Damyon Wiese
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\output;
  27  
  28  use Mustache_LambdaHelper;
  29  use renderer_base;
  30  
  31  /**
  32   * This class will call pix_icon with the section content.
  33   *
  34   * @copyright  2015 Damyon Wiese
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   * @since      2.9
  37   */
  38  class mustache_pix_helper {
  39  
  40      /** @var renderer_base $renderer A reference to the renderer in use */
  41      private $renderer;
  42  
  43      /**
  44       * Save a reference to the renderer.
  45       * @param renderer_base $renderer
  46       */
  47      public function __construct(renderer_base $renderer) {
  48          $this->renderer = $renderer;
  49      }
  50  
  51      /**
  52       * Read a pix icon name from a template and get it from pix_icon.
  53       *
  54       * {{#pix}}t/edit,component,Anything else is alt text{{/pix}}
  55       *
  56       * The args are comma separated and only the first is required.
  57       *
  58       * @param string $text The text to parse for arguments.
  59       * @param Mustache_LambdaHelper $helper Used to render nested mustache variables.
  60       * @return string
  61       */
  62      public function pix($text, Mustache_LambdaHelper $helper) {
  63          // Split the text into an array of variables.
  64          $key = strtok($text, ",");
  65          $key = trim($key);
  66          $component = strtok(",");
  67          $component = trim($component);
  68          if (!$component) {
  69              $component = '';
  70          }
  71          $text = strtok("");
  72          // Allow mustache tags in the last argument.
  73          $text = $helper->render($text);
  74  
  75          return trim($this->renderer->pix_icon($key, $text, $component));
  76      }
  77  }
  78  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1