MDL-49152 output: Templates for renderers (JS and PHP)

Mustache support for rendering templates from either php or js.
This commit is contained in:
Damyon Wiese
2015-03-14 22:48:40 +08:00
parent 72f8324ec5
commit 9bdcf57951
66 changed files with 6532 additions and 33 deletions
+38 -20
View File
@@ -293,6 +293,42 @@ class page_requirements_manager {
$this->js_module($this->find_module('core_filepicker'));
}
/**
* Return the safe config values that get set for javascript in "M.cfg".
*
* @since 2.9
* @return array List of safe config values that are available to javascript.
*/
public function get_config_for_javascript(moodle_page $page, renderer_base $renderer) {
global $CFG;
if (empty($this->M_cfg)) {
// JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
// Otherwise, in some situations, users will get warnings about insecure content
// on secure pages from their web browser.
$this->M_cfg = array(
'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above.
'sesskey' => sesskey(),
'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false),
'themerev' => theme_get_revision(),
'slasharguments' => (int)(!empty($CFG->slasharguments)),
'theme' => $page->theme->name,
'jsrev' => $this->get_jsrev(),
'admin' => $CFG->admin,
'svgicons' => $page->theme->use_svg_icons()
);
if ($CFG->debugdeveloper) {
$this->M_cfg['developerdebug'] = true;
}
if (defined('BEHAT_SITE_RUNNING')) {
$this->M_cfg['behatsiterunning'] = true;
}
}
return $this->M_cfg;
}
/**
* Initialise with the bits of JavaScript that every Moodle page should have.
*
@@ -302,26 +338,8 @@ class page_requirements_manager {
protected function init_requirements_data(moodle_page $page, core_renderer $renderer) {
global $CFG;
// JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
// Otherwise, in some situations, users will get warnings about insecure content
// on secure pages from their web browser.
$this->M_cfg = array(
'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above.
'sesskey' => sesskey(),
'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false),
'themerev' => theme_get_revision(),
'slasharguments' => (int)(!empty($CFG->slasharguments)),
'theme' => $page->theme->name,
'jsrev' => $this->get_jsrev(),
'svgicons' => $page->theme->use_svg_icons()
);
if ($CFG->debugdeveloper) {
$this->M_cfg['developerdebug'] = true;
}
if (defined('BEHAT_SITE_RUNNING')) {
$this->M_cfg['behatsiterunning'] = true;
}
// Init the js config.
$this->get_config_for_javascript($page, $renderer);
// Accessibility stuff.
$this->skip_link_to('maincontent', get_string('tocontent', 'access'));