From: jdlrobson Date: Wed, 17 Dec 2014 20:30:54 +0000 (-0800) Subject: resourceloader: Add template compiler for Mustache JS X-Git-Tag: 1.31.0-rc.0~12015^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=7c52c9265be1a3e3a4183515f4da7e189b321a88 resourceloader: Add template compiler for Mustache JS Compatible library for PHP backend added by I281acc49c1. This adds the frontend compiler. Change-Id: I2190276a629ca882f3f5535e4e73635d2494e944 --- diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 0104fe9c5e..a46c9316c5 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -295,6 +295,18 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { } if ( $hasTemplates ) { $this->dependencies[] = 'mediawiki.template'; + // Ensure relevant template compiler module gets loaded + foreach ( $this->templates as $alias => $templatePath ) { + if ( is_int( $alias ) ) { + $alias = $templatePath; + } + $suffix = explode( '.', $alias ); + $suffix = end( $suffix ); + $compilerModule = 'mediawiki.template.' . $suffix; + if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies ) ) { + $this->dependencies[] = $compilerModule; + } + } } } diff --git a/resources/Resources.php b/resources/Resources.php index 2c80a8535b..0b751f63c0 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -791,6 +791,12 @@ return array( 'scripts' => 'resources/src/mediawiki/mediawiki.template.js', 'targets' => array( 'desktop', 'mobile' ), ), + 'mediawiki.template.mustache' => array( + 'scripts' => array( + 'resources/lib/mustache/mustache.js', + 'resources/src/mediawiki/mediawiki.template.mustache.js', + ), + ), 'mediawiki.apipretty' => array( 'styles' => 'resources/src/mediawiki/mediawiki.apipretty.css', 'targets' => array( 'desktop', 'mobile' ), diff --git a/resources/lib/mustache/mustache.js b/resources/lib/mustache/mustache.js new file mode 100644 index 0000000000..dbc9823195 --- /dev/null +++ b/resources/lib/mustache/mustache.js @@ -0,0 +1,578 @@ +/*! + * mustache.js - Logic-less {{mustache}} templates with JavaScript + * http://github.com/janl/mustache.js + */ + +/*global define: false*/ + +(function (global, factory) { + if (typeof exports === "object" && exports) { + factory(exports); // CommonJS + } else if (typeof define === "function" && define.amd) { + define(['exports'], factory); // AMD + } else { + factory(global.Mustache = {}); //