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

Partials compiler should be non-destructive

tags/0.5.0-vsc
unknown 16 лет назад
Родитель
Сommit
98cdab2af5
2 измененных файлов: 13 добавлений и 2 удалений
  1. +8
    -1
      mustache.js
  2. +5
    -1
      test/unit.compiler.js

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

@@ -773,11 +773,18 @@ var Mustache = function() {
} }
}, },
compile: function(template, partials) { compile: function(template, partials) {
var p = {};
for (var key in partials) {
if (partials.hasOwnProperty(key)) {
p[key] = partials[key];
}
}
var commands = []; var commands = [];
var s = function(command) { commands.push(command); }; var s = function(command) { commands.push(command); };
var renderer = new Renderer(s, 'compiler'); var renderer = new Renderer(s, 'compiler');
renderer.render(template, {}, partials);
renderer.render(template, {}, p);


return function(view, send_func) { return function(view, send_func) {
var o = send_func ? undefined : []; var o = send_func ? undefined : [];


+ 5
- 1
test/unit.compiler.js Просмотреть файл

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


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


// matches whitespace_partial.html // matches whitespace_partial.html
equals( equals(
@@ -67,6 +67,10 @@ test("Parser", function() {
equals(e.message, 'Unexpected end of document.'); equals(e.message, 'Unexpected end of document.');
} }
var partials = { 'partial' : '{{key}}' };
Mustache.compile('{{>partial}}', partials );
equals(partials['partial'], '{{key}}', 'Partials compiler must be non-destructive');
}); });


test("Basic Variables", function() { test("Basic Variables", function() {


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