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

Allow compiling of tokens without template

This commit allows pre-compiled templates to be executed without
keeping the original template around. It is still required when using
higher-order functions.

Fixes #262
tags/0.7.3
Michael Jackson 13 лет назад
Родитель
Сommit
0d8b00fa67
2 измененных файлов: 12 добавлений и 5 удалений
  1. +7
    -0
      CHANGES
  2. +5
    -5
      mustache.js

+ 7
- 0
CHANGES Просмотреть файл

@@ -1,3 +1,10 @@
= HEAD

* Don't require the original template to be passed to the rendering function
when using compiled templates. This is still required when using higher-order
functions in order to be able to extract the portion of the template
that was contained by that section. Fixes #262

= 0.7.2 / 27 Dec 2012 = 0.7.2 / 27 Dec 2012


* Fixed a rendering bug (#274) when using nested higher-order sections. * Fixed a rendering bug (#274) when using nested higher-order sections.


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

@@ -230,7 +230,8 @@
return this.compile(template)(view, partials); return this.compile(template)(view, partials);
}; };


Writer.prototype._section = function (name, context, text, callback) {
Writer.prototype._section = function (token, context, template, callback) {
var name = token[1];
var value = context.lookup(name); var value = context.lookup(name);


switch (typeof value) { switch (typeof value) {
@@ -247,6 +248,7 @@


return value ? callback(this, context.push(value)) : ""; return value ? callback(this, context.push(value)) : "";
case "function": case "function":
var text = template == null ? null : template.slice(token[3], token[5]);
var self = this; var self = this;
var scopedRender = function (template) { var scopedRender = function (template) {
return self.render(template, context); return self.render(template, context);
@@ -319,15 +321,13 @@


return function (writer, context, template) { return function (writer, context, template) {
var buffer = ""; var buffer = "";
var token, sectionText;


var token;
for (var i = 0, len = tokens.length; i < len; ++i) { for (var i = 0, len = tokens.length; i < len; ++i) {
token = tokens[i]; token = tokens[i];

switch (token[0]) { switch (token[0]) {
case "#": case "#":
sectionText = template.slice(token[3], token[5]);
buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template));
buffer += writer._section(token, context, template, subRender(i, token[4], template));
break; break;
case "^": case "^":
buffer += writer._inverted(token[1], context, subRender(i, token[4], template)); buffer += writer._inverted(token[1], context, subRender(i, token[4], template));


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