ソースを参照

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年前
コミット
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

* 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);
};

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);

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

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

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

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

switch (token[0]) {
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;
case "^":
buffer += writer._inverted(token[1], context, subRender(i, token[4], template));


読み込み中…
キャンセル
保存