api.js: Add an else to avoid unnecessary checks
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.template.mustache.js
index 624986a..9f5e5c4 100644 (file)
@@ -1,11 +1,31 @@
-/*global Mustache */
+/* global Mustache */
 ( function ( mw, $ ) {
        // Register mustache compiler
        mw.template.registerCompiler( 'mustache', {
                compile: function ( src ) {
                        return {
-                               render: function ( data ) {
-                                       return $( $.parseHTML( Mustache.render( src, data ) ) );
+                               /**
+                                * @ignore
+                                * @return {string} The raw source code of the template
+                                */
+                               getSource: function () {
+                                       return src;
+                               },
+                               /**
+                                * @ignore
+                                * @param {Object} data Data to render
+                                * @param {Object} partialTemplates Map partial names to Mustache template objects
+                                *  returned by mw.template.get()
+                                * @return {jQuery} Rendered HTML
+                                */
+                               render: function ( data, partialTemplates ) {
+                                       var partials = {};
+                                       if ( partialTemplates ) {
+                                               $.each( partialTemplates, function ( name, template ) {
+                                                       partials[ name ] = template.getSource();
+                                               } );
+                                       }
+                                       return $( $.parseHTML( Mustache.render( src, data, partials ) ) );
                                }
                        };
                }