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
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"
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"
end
+11 -8
View File
@@ -1,13 +1,16 @@
var Handlebars = require("handlebars/compiler").Handlebars;
Handlebars.AST = require("handlebars/ast").AST;
Handlebars.HandlebarsLexer = require("handlebars/handlebars_lexer").Lexer;
Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor;
Handlebars.Runtime = require("handlebars/runtime").Runtime;
Handlebars.Context = require("Handlebars/runtime").Context;
Handlebars.Utils = require("handlebars/utils").Utils;
Handlebars.SafeString = require("handlebars/utils").SafeString;
Handlebars.Exception = require("handlebars/utils").Exception;
Handlebars.AST = require("handlebars/ast").AST;
Handlebars.HandlebarsLexer = require("handlebars/handlebars_lexer").Lexer;
Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor;
Handlebars.Runtime = require("handlebars/runtime").Runtime;
Handlebars.Context = require("Handlebars/runtime").Context;
Handlebars.Utils = require("handlebars/utils").Utils;
Handlebars.SafeString = require("handlebars/utils").SafeString;
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)
+3 -2
View File
@@ -64,8 +64,9 @@ Handlebars.Exception = require("handlebars/utils").Exception;
else { dig.push(part); }
}
this.parts = dig;
this.depth = depth;
this.parts = dig;
this.depth = depth;
this.isSimple = (dig.length === 1) && (depth === 0)
};
Handlebars.AST.StringNode = function(string) {
+1 -1
View File
@@ -104,7 +104,7 @@ Handlebars.Runtime.prototype = {
mustache: function(mustache) {
var idObj = this.ID(mustache.id);
var params = mustache.params;
var params = mustache.params.slice(0);
var buf;
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();
};
Handlebars.Utils = {
escapeExpression: function(string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof Handlebars.SafeString) {
return string.toString();
}
else if (string === null) {
string = "";
}
(function() {
var escape = {
"<": "&lt;",
">": "&gt;",
};
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
switch(str) {
case "&":
return "&amp;";
case '"':
return "\"";
case "\\":
return "\\\\";
case "<":
return "&lt;";
case ">":
return "&gt;";
default:
return str;
var badChars = /&(?!\w+;)|[<>]/g;
var possible = /[&<>]/
var escapeChar = function(chr) {
return escape[chr] || "&amp;"
};
Handlebars.Utils = {
escapeExpression: function(string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof Handlebars.SafeString) {
return string.toString();
} else if (string === null) {
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)
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 template = Handlebars.compile(string);
var template = Handlebars.VM.compile(string);
if(Object.prototype.toString.call(hash) === "[object Array]") {
if(hash[1]) {
for(var prop in Handlebars.helpers) {
@@ -80,7 +80,7 @@ test("escaping expressions", function() {
shouldCompileTo("{{{awesome}}}", {awesome: "&\"\\<>"}, '&\"\\<>',
"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");
shouldCompileTo("{{&awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
@@ -452,7 +452,7 @@ test("block multi-params work", function() {
var string = 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}';
var hash = {cruel: "cruel", world: "world"}
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");
})
+6 -1
View File
@@ -54,10 +54,14 @@ module Handlebars
context["exports"] = nil
context["p"] = proc do |val|
p val
p val if ENV["DEBUG_JS"]
end
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
end
@@ -76,6 +80,7 @@ module Handlebars
Handlebars::Spec.js_load('lib/handlebars/printer.js')
Handlebars::Spec.js_load('lib/handlebars/runtime.js')
Handlebars::Spec.js_load('lib/handlebars/utils.js')
Handlebars::Spec.js_load('lib/Handlebars/vm.js')
Handlebars::Spec.js_load('lib/handlebars.js')
end
end