From 0bb4776deffd738478a217094e7709cbbcd34095 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 14 Nov 2009 14:50:29 +0100 Subject: [PATCH] mustache compat: Don't barf on unknown variables. --- examples/error_not_found.txt | 2 +- mustache.js | 3 ++- test/mustache_spec.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/error_not_found.txt b/examples/error_not_found.txt index fc8d6b7..8b13789 100644 --- a/examples/error_not_found.txt +++ b/examples/error_not_found.txt @@ -1 +1 @@ -ERROR: 'foo' not found in context + diff --git a/mustache.js b/mustache.js index 5050936..e52b378 100644 --- a/mustache.js +++ b/mustache.js @@ -158,7 +158,8 @@ var Mustache = function() { if(context[name] !== undefined) { return context[name]; } - throw({message: "'" + name + "' not found in context"}); + // silently ignore unkown variables + return ""; }, // Utility methods diff --git a/test/mustache_spec.rb b/test/mustache_spec.rb index f4bbb22..6f8a1bf 100644 --- a/test/mustache_spec.rb +++ b/test/mustache_spec.rb @@ -37,7 +37,7 @@ describe "mustache" do print('ERROR: ' + e.message); } JS - run_js(js).should == "ERROR: 'x' not found in context\n" + run_js(js).should == "\n" end non_partials.each do |testname|