From 4694868fdc20e045575b45af57c7aa1c22f44ad0 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 24 Mar 2010 01:07:47 -0700 Subject: [PATCH] don't barf on undefined partial contexts, return the verbatim partial instead --- CHANGES.md | 1 + examples/empty_partial.2.html | 1 + examples/empty_partial.html | 2 ++ examples/empty_partial.js | 3 +++ examples/empty_partial.txt | 2 ++ mustache.js | 6 +++--- 6 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 examples/empty_partial.2.html create mode 100644 examples/empty_partial.html create mode 100644 examples/empty_partial.js create mode 100644 examples/empty_partial.txt diff --git a/CHANGES.md b/CHANGES.md index 7208204..01d3044 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ * Added more robust type detection. * Parse pragmas only once. * Throw exception when encountering an unknown pragma. +* Ignore undefined partial contexts. Returns verbatim partials. ## 0.2.2 (11-02-2010) diff --git a/examples/empty_partial.2.html b/examples/empty_partial.2.html new file mode 100644 index 0000000..b920295 --- /dev/null +++ b/examples/empty_partial.2.html @@ -0,0 +1 @@ +yo \ No newline at end of file diff --git a/examples/empty_partial.html b/examples/empty_partial.html new file mode 100644 index 0000000..a710047 --- /dev/null +++ b/examples/empty_partial.html @@ -0,0 +1,2 @@ +hey {{foo}} +{{>partial}} diff --git a/examples/empty_partial.js b/examples/empty_partial.js new file mode 100644 index 0000000..9cc53c6 --- /dev/null +++ b/examples/empty_partial.js @@ -0,0 +1,3 @@ +var partial_context = { + foo: 1 +}; diff --git a/examples/empty_partial.txt b/examples/empty_partial.txt new file mode 100644 index 0000000..90d2b9f --- /dev/null +++ b/examples/empty_partial.txt @@ -0,0 +1,2 @@ +hey 1 +yo diff --git a/mustache.js b/mustache.js index 25d8390..eab1a9f 100644 --- a/mustache.js +++ b/mustache.js @@ -85,12 +85,12 @@ var Mustache = function() { Tries to find a partial in the global scope and render it */ render_partial: function(name, context, partials) { - if(typeof(context[name]) != "object") { - throw({message: "subcontext for '" + name + "' is not an object"}); - } if(!partials || !partials[name]) { throw({message: "unknown_partial '" + name + "'"}); } + if(typeof(context[name]) != "object") { + return partials[name]; + } return this.render(partials[name], context[name], partials, true); },