Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace core\output;
18
 
19
/**
20
 * Perform some custom name mapping for template file names.
21
 *
1441 ariadna 22
 * @package core
1 efrain 23
 * @copyright  2015 Damyon Wiese
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @since      2.9
26
 */
27
class mustache_filesystem_loader extends \Mustache_Loader_FilesystemLoader {
28
    /**
29
     * Provide a default no-args constructor (we don't really need anything).
30
     */
31
    public function __construct() {
32
    }
33
 
34
    /**
35
     * Helper function for getting a Mustache template file name.
36
     * Uses the leading component to restrict us specific directories.
37
     *
38
     * @param string $name
39
     * @return string Template file name
40
     */
1441 ariadna 41
    protected function getfilename($name) {
1 efrain 42
        // Call the Moodle template finder.
43
        return mustache_template_finder::get_template_filepath($name);
44
    }
45
 
46
    /**
47
     * Only check if baseDir is a directory and requested templates are files if
48
     * baseDir is using the filesystem stream wrapper.
49
     *
50
     * Always check path for mustache_filesystem_loader.
51
     *
52
     * @return bool Whether to check `is_dir` and `file_exists`
53
     */
1441 ariadna 54
    protected function shouldcheckpath() {
1 efrain 55
        return true;
56
    }
57
 
58
    /**
59
     * Load a Template by name.
60
     *
61
     * @param string $name the template name
62
     * @return string Mustache Template source
63
     */
64
    public function load($name) {
65
        global $CFG;
66
        if (!empty($CFG->debugtemplateinfo)) {
67
            // We use many templates per page. We don't want to allocate more memory than necessary.
68
            return "<!-- template(PHP): $name -->" . parent::load($name) . "<!-- /template(PHP): $name -->";
69
        }
70
        return parent::load($name);
71
    }
72
}