Support mustache partials in server-side templates
authorS Page <spage@wikimedia.org>
Tue, 7 Jul 2015 01:32:21 +0000 (18:32 -0700)
committerS Page <spage@wikimedia.org>
Tue, 7 Jul 2015 03:13:45 +0000 (20:13 -0700)
This is sufficient to make https://gerrit.wikimedia.org/r/#/c/223165/
work.  It hardcodes .mustache as the extension, but so does
existing getTemplateFilename().

Bug: T97188
Change-Id: Id588ae9b43b13fcf35ebd285c826dd502ac424ec

includes/TemplateParser.php
tests/phpunit/data/templates/bad_partial.mustache [new file with mode: 0644]
tests/phpunit/data/templates/has_partial.mustache [new file with mode: 0644]
tests/phpunit/includes/TemplateParserTest.php

index d53d593..f0a1ebb 100644 (file)
@@ -173,7 +173,9 @@ class TemplateParser {
                        array(
                                // Do not add more flags here without discussion.
                                // If you do add more flags, be sure to update unit tests as well.
-                               'flags' => LightnCandy::FLAG_ERROR_EXCEPTION
+                               'flags' => LightnCandy::FLAG_ERROR_EXCEPTION,
+                               'basedir' => $this->templateDir,
+                               'fileext' => '.mustache',
                        )
                );
        }
diff --git a/tests/phpunit/data/templates/bad_partial.mustache b/tests/phpunit/data/templates/bad_partial.mustache
new file mode 100644 (file)
index 0000000..d2767f0
--- /dev/null
@@ -0,0 +1 @@
+Partial {{>nonexistenttemplate}} in here
diff --git a/tests/phpunit/data/templates/has_partial.mustache b/tests/phpunit/data/templates/has_partial.mustache
new file mode 100644 (file)
index 0000000..504387a
--- /dev/null
@@ -0,0 +1 @@
+Partial {{>foobar_args}} in here
index 81854ff..3b37f4a 100644 (file)
@@ -57,7 +57,20 @@ class TemplateParserTest extends MediaWikiTestCase {
                                array(),
                                false,
                                'RuntimeException',
-                       )
+                       ),
+                       array(
+                               'has_partial',
+                               array(
+                                       'planet' => 'world',
+                               ),
+                               "Partial hello world!\n in here\n",
+                       ),
+                       array(
+                               'bad_partial',
+                               array(),
+                               false,
+                               'Exception',
+                       ),
                );
        }
 }