Everything is working now on the new VM except for partials and inverse sections

This commit is contained in:
wycats
2010-12-15 23:42:53 -08:00
parent ec948c7382
commit e15d675a64
7 changed files with 64 additions and 55 deletions
+2 -2
View File
@@ -20,11 +20,11 @@ def remove_exports(string)
match ? match[1] : string match ? match[1] : string
end end
minimal_deps = %w(parser compiler ast jison_ext handlebars_lexer runtime utils).map do |file| minimal_deps = %w(parser compiler ast jison_ext handlebars_lexer runtime utils vm).map do |file|
"lib/handlebars/#{file}.js" "lib/handlebars/#{file}.js"
end end
debug_deps = %w(parser compiler ast jison_ext handlebars_lexer printer runtime utils).map do |file| debug_deps = %w(parser compiler ast jison_ext handlebars_lexer printer runtime utils vm).map do |file|
"lib/handlebars/#{file}.js" "lib/handlebars/#{file}.js"
end end
+11 -8
View File
@@ -1,13 +1,16 @@
var Handlebars = require("handlebars/compiler").Handlebars; var Handlebars = require("handlebars/compiler").Handlebars;
Handlebars.AST = require("handlebars/ast").AST; Handlebars.AST = require("handlebars/ast").AST;
Handlebars.HandlebarsLexer = require("handlebars/handlebars_lexer").Lexer; Handlebars.HandlebarsLexer = require("handlebars/handlebars_lexer").Lexer;
Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor; Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor;
Handlebars.Runtime = require("handlebars/runtime").Runtime; Handlebars.Runtime = require("handlebars/runtime").Runtime;
Handlebars.Context = require("Handlebars/runtime").Context; Handlebars.Context = require("Handlebars/runtime").Context;
Handlebars.Utils = require("handlebars/utils").Utils; Handlebars.Utils = require("handlebars/utils").Utils;
Handlebars.SafeString = require("handlebars/utils").SafeString; Handlebars.SafeString = require("handlebars/utils").SafeString;
Handlebars.Exception = require("handlebars/utils").Exception; Handlebars.Exception = require("handlebars/utils").Exception;
Handlebars.Compiler = require("handlebars/vm").Compiler;
Handlebars.JavaScriptCompiler = require("handlebars/vm").JavaScriptCompiler;
Handlebars.VM = require("handlebars/vm").VM;
// BEGIN(BROWSER) // BEGIN(BROWSER)
+3 -2
View File
@@ -64,8 +64,9 @@ Handlebars.Exception = require("handlebars/utils").Exception;
else { dig.push(part); } else { dig.push(part); }
} }
this.parts = dig; this.parts = dig;
this.depth = depth; this.depth = depth;
this.isSimple = (dig.length === 1) && (depth === 0)
}; };
Handlebars.AST.StringNode = function(string) { Handlebars.AST.StringNode = function(string) {
+1 -1
View File
@@ -104,7 +104,7 @@ Handlebars.Runtime.prototype = {
mustache: function(mustache) { mustache: function(mustache) {
var idObj = this.ID(mustache.id); var idObj = this.ID(mustache.id);
var params = mustache.params; var params = mustache.params.slice(0);
var buf; var buf;
for(var i=0, l=params.length; i<l; i++) { for(var i=0, l=params.length; i<l; i++) {
+38 -38
View File
@@ -13,47 +13,47 @@ Handlebars.SafeString.prototype.toString = function() {
return this.string.toString(); return this.string.toString();
}; };
Handlebars.Utils = { (function() {
escapeExpression: function(string) { var escape = {
// don't escape SafeStrings, since they're already safe "<": "&lt;",
if (string instanceof Handlebars.SafeString) { ">": "&gt;",
return string.toString(); };
}
else if (string === null) {
string = "";
}
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) { var badChars = /&(?!\w+;)|[<>]/g;
switch(str) { var possible = /[&<>]/
case "&":
return "&amp;"; var escapeChar = function(chr) {
case '"': return escape[chr] || "&amp;"
return "\""; };
case "\\":
return "\\\\"; Handlebars.Utils = {
case "<": escapeExpression: function(string) {
return "&lt;"; // don't escape SafeStrings, since they're already safe
case ">": if (string instanceof Handlebars.SafeString) {
return "&gt;"; return string.toString();
default: } else if (string === null) {
return str; string = "";
}
if(!possible.test(string)) { return string; }
return string.replace(badChars, escapeChar);
},
isEmpty: function(value) {
if (typeof value === "undefined") {
return true;
} else if (value === null) {
return true;
} else if (value === false) {
return true;
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
return true;
} else {
return false;
} }
});
},
isEmpty: function(value) {
if (typeof value === "undefined") {
return true;
} else if (value === null) {
return true;
} else if (value === false) {
return true;
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
return true;
} else {
return false;
} }
} };
}; })();
// END(BROWSER) // END(BROWSER)
exports.Utils = Handlebars.Utils; exports.Utils = Handlebars.Utils;
+3 -3
View File
@@ -7,7 +7,7 @@ Handlebars.registerHelper('helperMissing', function(helper, context) {
}); });
var shouldCompileTo = function(string, hash, expected, message) { var shouldCompileTo = function(string, hash, expected, message) {
var template = Handlebars.compile(string); var template = Handlebars.VM.compile(string);
if(Object.prototype.toString.call(hash) === "[object Array]") { if(Object.prototype.toString.call(hash) === "[object Array]") {
if(hash[1]) { if(hash[1]) {
for(var prop in Handlebars.helpers) { for(var prop in Handlebars.helpers) {
@@ -80,7 +80,7 @@ test("escaping expressions", function() {
shouldCompileTo("{{{awesome}}}", {awesome: "&\"\\<>"}, '&\"\\<>', shouldCompileTo("{{{awesome}}}", {awesome: "&\"\\<>"}, '&\"\\<>',
"expressions with 3 handlebars aren't escaped"); "expressions with 3 handlebars aren't escaped");
shouldCompileTo("{{awesome}}", {awesome: "&\"\\<>"}, '&amp;\"\\\\&lt;&gt;', shouldCompileTo("{{awesome}}", {awesome: "&\"\\<>"}, '&amp;\"\\&lt;&gt;',
"by default expressions should be escaped"); "by default expressions should be escaped");
shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>', shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
@@ -452,7 +452,7 @@ test("block multi-params work", function() {
var string = 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}'; var string = 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}';
var hash = {cruel: "cruel", world: "world"} var hash = {cruel: "cruel", world: "world"}
var fallback = {goodbye: function(cruel, world, fn) { var fallback = {goodbye: function(cruel, world, fn) {
return fn({greeting: "Goodbye", adj: "cruel", noun: "world"}); return fn({greeting: "Goodbye", adj: cruel, noun: world});
}} }}
shouldCompileTo(string, [hash, fallback], "Message: Goodbye cruel world", "block helpers with multiple params"); shouldCompileTo(string, [hash, fallback], "Message: Goodbye cruel world", "block helpers with multiple params");
}) })
+6 -1
View File
@@ -54,10 +54,14 @@ module Handlebars
context["exports"] = nil context["exports"] = nil
context["p"] = proc do |val| context["p"] = proc do |val|
p val p val if ENV["DEBUG_JS"]
end end
context["puts"] = proc do |val| context["puts"] = proc do |val|
puts val if ENV["DEBUG_JS"]
end
context["puts_node"] = proc do |val|
puts context["Handlebars"]["PrintVisitor"].new.accept(val) puts context["Handlebars"]["PrintVisitor"].new.accept(val)
puts puts
end end
@@ -76,6 +80,7 @@ module Handlebars
Handlebars::Spec.js_load('lib/handlebars/printer.js') Handlebars::Spec.js_load('lib/handlebars/printer.js')
Handlebars::Spec.js_load('lib/handlebars/runtime.js') Handlebars::Spec.js_load('lib/handlebars/runtime.js')
Handlebars::Spec.js_load('lib/handlebars/utils.js') Handlebars::Spec.js_load('lib/handlebars/utils.js')
Handlebars::Spec.js_load('lib/Handlebars/vm.js')
Handlebars::Spec.js_load('lib/handlebars.js') Handlebars::Spec.js_load('lib/handlebars.js')
end end
end end