Просмотр исходного кода

Add Chris's toSource() for error messages.

with-js-extras
Paul J. Davis 16 лет назад
Родитель
Сommit
5b0a26827a
5 измененных файлов: 10 добавлений и 11 удалений
  1. +1
    -1
      examples/error_nested_array_bounds.txt
  2. +1
    -1
      examples/error_nested_missing.txt
  3. +1
    -1
      examples/error_not_found.txt
  4. +6
    -7
      mustache.js
  5. +1
    -1
      test/mustache_spec.rb

+ 1
- 1
examples/error_nested_array_bounds.txt Просмотреть файл

@@ -1 +1 @@
ERROR: 'foo.5' not found in context
ERROR: 'foo.5' not found in context: {foo:[1, 2]}

+ 1
- 1
examples/error_nested_missing.txt Просмотреть файл

@@ -1 +1 @@
ERROR: 'foo.bar' not found in context
ERROR: 'foo.bar' not found in context: {not_foo:{not_bar:"yay error!"}}

+ 1
- 1
examples/error_not_found.txt Просмотреть файл

@@ -1 +1 @@
ERROR: 'foo' not found in context
ERROR: 'foo' not found in context: {bar:2}

+ 6
- 7
mustache.js Просмотреть файл

@@ -30,10 +30,10 @@ var Mustache = function() {
*/
render_partial: function(name, context, partials) {
if(typeof(context[name]) != "object") {
throw({message: "subcontext for '" + name + "' is not an object"});
throw({message: "Context for '" + name + "' is not an object."});
}
if(!partials || !partials[name]) {
throw({message: "unknown_partial"});
throw({message: "No template for partial '" + name + "'."});
}
return this.render(partials[name], context[name], partials);
},
@@ -134,10 +134,7 @@ var Mustache = function() {
if(typeof value === "function") {
return value.apply(context);
}
if(value !== undefined) {
return value;
}
throw({message: "'" + name + "' not found in context"});
return value;
},

// Utility methods
@@ -167,7 +164,9 @@ var Mustache = function() {
while(parts.length) {
p = parts.shift();
if(ctx[p] === undefined) {
throw({message: "'" + name + "' not found in context"});
src = context.toSource();
src = src.replace(/^\(|\)$/g, "");
throw({message: "'" + name + "' not found in context: " + src});
}
ctx = ctx[p];
}


+ 1
- 1
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 == "ERROR: 'x' not found in context: {list:[{}]}\n"
end
non_partials.each do |testname|


Загрузка…
Отмена
Сохранить