2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Mustache helper render pix icons.
22 * @copyright 2015 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace core\output
;
28 use Mustache_LambdaHelper
;
32 * This class will call pix_icon with the section content.
34 * @copyright 2015 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class mustache_pix_helper
{
40 /** @var renderer_base $renderer A reference to the renderer in use */
44 * Save a reference to the renderer.
45 * @param renderer_base $renderer
47 public function __construct(renderer_base
$renderer) {
48 $this->renderer
= $renderer;
52 * Read a pix icon name from a template and get it from pix_icon.
54 * {{#pix}}t/edit,component,Anything else is alt text{{/pix}}
56 * The args are comma separated and only the first is required.
58 * @param string $text The text to parse for arguments.
59 * @param Mustache_LambdaHelper $helper Used to render nested mustache variables.
62 public function pix($text, Mustache_LambdaHelper
$helper) {
63 // Split the text into an array of variables.
64 $key = strtok($text, ",");
65 $key = trim($helper->render($key));
66 $component = strtok(",");
67 $component = trim($helper->render($component));
71 $component = $helper->render($component);
73 // Allow mustache tags in the last argument.
74 $text = trim($helper->render($text));
76 return trim($this->renderer
->pix_icon($key, $text, $component));