Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow compiled templates to be used as partials. #191

Open
wants to merge 1 commit into from

1 participant

@magcius

It should be possible to use an already compiled template as a partial.

@magcius magcius Allow using a compiled template as a partial
It should be possible to use an already compiled template as a partial.
a8783db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2012
  1. @magcius

    Allow using a compiled template as a partial

    magcius authored
    It should be possible to use an already compiled template as a partial.
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 mustache.js
View
8 mustache.js
@@ -476,7 +476,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// This anonymous function wraps the generated function so we can do
// argument coercion, setup some variables, and handle any errors
// encountered while executing it.
- return function (view, partials) {
+ var template = function (view, partials) {
partials = partials || {};
var stack = [view]; // context stack
@@ -487,6 +487,8 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
throw debug(e.error, template, e.line, options.file);
}
};
+ template.compiled = true;
+ return template;
}
// Cache of pre-compiled templates.
@@ -511,6 +513,10 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
function compile(template, options) {
options = options || {};
+ if (typeof template === "function" && template.compiled) {
+ return template;
+ }
+
// Use a pre-compiled version from the cache if we have one.
if (options.cache !== false) {
if (!_cache[template]) {
Something went wrong with that request. Please try again.