Sfoglia il codice sorgente

pass all tests in both interpreter and compiler mode

tags/0.5.0-vsc
unknown 16 anni fa
parent
commit
afbb2089db
2 ha cambiato i file con 39 aggiunte e 37 eliminazioni
  1. +36
    -26
      mustache.js
  2. +3
    -11
      test/unit.compiler.js

+ 36
- 26
mustache.js Vedi File

@@ -575,19 +575,22 @@ var Mustache = function() {
var result = value.call(contextStack[contextStack.length-1], mustacheFragment, function(resultFragment) { var result = value.call(contextStack[contextStack.length-1], mustacheFragment, function(resultFragment) {
var tempStream = []; var tempStream = [];
var old_send_func = that.send_func;
that.send_func = function(text) { tempStream.push(text); };
var old_send_func = that.user_send_func;
that.user_send_func = function(text) { tempStream.push(text); };
tokens = that.tokenize(resultFragment, openTag, closeTag); tokens = that.tokenize(resultFragment, openTag, closeTag);
that.parse(that.createParserContext(tokens, partials, openTag, closeTag), contextStack); that.parse(that.createParserContext(tokens, partials, openTag, closeTag), contextStack);
that.send_func = old_send_func;
that.user_send_func = old_send_func;
return tempStream.join(''); return tempStream.join('');
}); });
this.user_send_func(result); this.user_send_func(result);
}
} else if (value) {
tokens = this.tokenize(mustacheFragment, openTag, closeTag);
this.parse(this.createParserContext(tokens, partials, openTag, closeTag), contextStack);
}
} else { } else {
throw new ParserException('Unknown section type ' + sectionType); throw new ParserException('Unknown section type ' + sectionType);
} }
@@ -632,30 +635,35 @@ var Mustache = function() {
throw new ParserException('Unknown partial \'' + key + '\''); throw new ParserException('Unknown partial \'' + key + '\'');
} }
var old_user_send_func = this.user_send_func;
var commands = [];
this.user_send_func = function(command) { commands.push(command); };
var tokens = this.tokenize(partials[key], openTag, closeTag);
this.parse(this.createParserContext(tokens, partials, openTag, closeTag), reserved);
this.user_send_func = old_user_send_func;
var that = this;
this.user_send_func(function(contextStack, send_func) {
var res = that.find_in_stack(key, contextStack);
if (that.is_object(res)) {
contextStack.push(res);
}
if (!this.is_function(partials[key])) {
var old_user_send_func = this.user_send_func;
var commands = [];
this.user_send_func = function(command) { commands.push(command); };
var tokens = this.tokenize(partials[key], openTag, closeTag);
partials[key] = function() {}; // blank out the paritals so that infinite recursion doesn't happen
this.parse(this.createParserContext(tokens, partials, openTag, closeTag), reserved);
for (var i=0,n=commands.length; i<n; ++i) {
commands[i](contextStack, send_func);
}
this.user_send_func = old_user_send_func;
if (that.is_object(res)) {
contextStack.pop();
}
});
var that = this;
partials[key] = function(contextStack, send_func) {
var res = that.find_in_stack(key, contextStack);
if (that.is_object(res)) {
contextStack.push(res);
}
for (var i=0,n=commands.length; i<n; ++i) {
commands[i](contextStack, send_func);
}
if (that.is_object(res)) {
contextStack.pop();
}
};
}
this.user_send_func(function(contextStack, send_func) { partials[key](contextStack, send_func); });
}, },
section: function(sectionType, mustacheFragment, key, reserved/*contextStack*/, partials, openTag, closeTag) { section: function(sectionType, mustacheFragment, key, reserved/*contextStack*/, partials, openTag, closeTag) {
// by @langalex, support for arrays of strings // by @langalex, support for arrays of strings
@@ -735,6 +743,8 @@ var Mustache = function() {
}); });
send_func(result); send_func(result);
} else if (value) {
section_command(contextStack, send_func);
} }
}); });
} else { } else {


+ 3
- 11
test/unit.compiler.js Vedi File

@@ -238,7 +238,7 @@ test("'#' (Sections)", function() {
}, },
{} {}
), ),
'\n t1\n 0\n t2\n 1\n\n t1\n 0\n t2\n 1\n\n',
'\n t1\n 0\n\n t2\n 1\n\n\n t1\n 0\n\n t2\n 1\n\n',
'Lazy match of Section and Inverted Section' 'Lazy match of Section and Inverted Section'
); );
@@ -255,7 +255,7 @@ test("'#' (Sections)", function() {
}, },
{} {}
), ),
'\n <h1>this is an object</h1>\n <p>one of its attributes is a list</p>\n <ul>\n <li>listitem1</li>\n <li>listitem2</li>\n </ul>\n',
'\n <h1>this is an object</h1>\n <p>one of its attributes is a list</p>\n <ul>\n \n <li>listitem1</li>\n \n <li>listitem2</li>\n \n </ul>\n\n',
'Lazy match of Section and Inverted Section' 'Lazy match of Section and Inverted Section'
); );
}); });
@@ -536,15 +536,7 @@ test("Demo", function() {
} }
}; };
var expected_result = [
'<h1>Colors</h1>',
' <ul>',
' <li><strong>red</strong></li>',
' <li><a href="#Green">green</a></li>',
' <li><a href="#Blue">blue</a></li>',
' </ul>',
''
].join('\n');
var expected_result = '<h1>Colors</h1>\n\n <ul>\n \n \n <li><strong>red</strong></li>\n \n \n <li><a href=\"#Red\">red</a></li>\n \n \n \n \n <li><a href=\"#Green\">green</a></li>\n \n \n \n \n <li><a href=\"#Blue\">blue</a></li>\n \n \n </ul>\n\n';
equals( equals(
Mustache.to_html( Mustache.to_html(


Loading…
Annulla
Salva