Ver código fonte

Beef up entry points for bad input checks.

tags/0.5.0-vsc
unknown 16 anos atrás
pai
commit
12d2fbb755
3 arquivos alterados com 38 adições e 5 exclusões
  1. +20
    -5
      mustache.js
  2. +9
    -0
      test/unit.compiler.js
  3. +9
    -0
      test/unit.interpreter.js

+ 20
- 5
mustache.js Ver arquivo

@@ -770,6 +770,11 @@ var Mustache = function() {
Turns a template and view into HTML
*/
to_html: function(template, view, partials, send_func) {
if (!template) { return ''; }
partials = partials || {};
view = view || {};
var o = send_func ? undefined : [];
var s = send_func || function(output) { o.push(output); };
@@ -780,11 +785,20 @@ var Mustache = function() {
return o.join('');
}
},
/*
Compiles a template into an equivalent JS function for faster
repeated execution.
*/
compile: function(template, partials) {
if (!template) { return function() { return '' }; }
var p = {};
for (var key in partials) {
if (partials.hasOwnProperty(key)) {
p[key] = partials[key];
if (partials) {
for (var key in partials) {
if (partials.hasOwnProperty(key)) {
p[key] = partials[key];
}
}
}
@@ -795,9 +809,10 @@ var Mustache = function() {
renderer.render(template, {}, p);

return function(view, send_func) {
var o = send_func ? undefined : [];
var s = send_func || function(output) { o.push(output); };
view = view || {};
var o = send_func ? undefined : [];
var s = send_func || function(output) { o.push(output); };
for (var i=0,n=commands.length; i<n; ++i) {
commands[i]([view], s);


+ 9
- 0
test/unit.compiler.js Ver arquivo

@@ -14,6 +14,15 @@ module('Compiler', {
}
});

test("Argument validation", function() {
expect(4);
equals(Mustache.to_html(undefined), '', 'No parameters');
equals(Mustache.to_html('{{hi}}'), '', ' No View or Partials');
equals(Mustache.to_html('{{hi}}', {hi:'Hi.'}), 'Hi.', 'No Partials');
equals(Mustache.to_html('{{>hi}}', undefined, {hi:'{{p}}'}), '', 'Partial but no view');
});

test("Parser", function() {
expect(4);



+ 9
- 0
test/unit.interpreter.js Ver arquivo

@@ -1,5 +1,14 @@
module('Interpreter');

test("Argument validation", function() {
expect(4);
equals(Mustache.to_html(undefined), '', 'No parameters');
equals(Mustache.to_html('{{hi}}'), '', ' No View or Partials');
equals(Mustache.to_html('{{hi}}', {hi:'Hi.'}), 'Hi.', 'No Partials');
equals(Mustache.to_html('{{>hi}}', undefined, {hi:'{{p}}'}), '', 'Partial but no view');
});

test("Parser", function() {
expect(3);



Carregando…
Cancelar
Salvar