Everything is working now on the new VM except for partials and inverse sections
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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 = {
|
||||
"<": "<",
|
||||
">": ">",
|
||||
};
|
||||
|
||||
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
|
||||
switch(str) {
|
||||
case "&":
|
||||
return "&";
|
||||
case '"':
|
||||
return "\"";
|
||||
case "\\":
|
||||
return "\\\\";
|
||||
case "<":
|
||||
return "<";
|
||||
case ">":
|
||||
return ">";
|
||||
default:
|
||||
return str;
|
||||
var badChars = /&(?!\w+;)|[<>]/g;
|
||||
var possible = /[&<>]/
|
||||
|
||||
var escapeChar = function(chr) {
|
||||
return escape[chr] || "&"
|
||||
};
|
||||
|
||||
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
@@ -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: "&\"\\<>"}, '&\"\\\\<>',
|
||||
shouldCompileTo("{{awesome}}", {awesome: "&\"\\<>"}, '&\"\\<>',
|
||||
"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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user