Break compiler and vm logic into separate files.
This commit is contained in:
@@ -28,11 +28,11 @@ def remove_exports(string)
|
||||
match ? match[1] : string
|
||||
end
|
||||
|
||||
minimal_deps = %w(parser base ast visitor utils compiler).map do |file|
|
||||
minimal_deps = %w(parser base ast visitor utils compiler/compiler vm).map do |file|
|
||||
"lib/handlebars/#{file}.js"
|
||||
end
|
||||
|
||||
debug_deps = %w(parser base ast visitor printer utils compiler debug).map do |file|
|
||||
debug_deps = %w(parser base ast visitor printer utils compiler/compiler vm debug).map do |file|
|
||||
"lib/handlebars/#{file}.js"
|
||||
end
|
||||
|
||||
|
||||
@@ -696,51 +696,5 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
|
||||
|
||||
Handlebars.VM = {
|
||||
programWithDepth: function(fn, helpers, partials, data, $depth) {
|
||||
var args = Array.prototype.slice.call(arguments, 4);
|
||||
|
||||
return function(context, options) {
|
||||
options = options || {};
|
||||
|
||||
options = {
|
||||
helpers: options.helpers || helpers,
|
||||
partials: options.partials || partials,
|
||||
data: options.data || data
|
||||
};
|
||||
|
||||
return fn.apply(this, [context, options].concat(args));
|
||||
};
|
||||
},
|
||||
program: function(fn, helpers, partials, data) {
|
||||
return function(context, options) {
|
||||
options = options || {};
|
||||
|
||||
return fn(context, {
|
||||
helpers: options.helpers || helpers,
|
||||
partials: options.partials || partials,
|
||||
data: options.data || data
|
||||
});
|
||||
};
|
||||
},
|
||||
noop: function() { return ""; },
|
||||
compile: function(string, options) {
|
||||
var ast = Handlebars.parse(string);
|
||||
var environment = new Handlebars.Compiler().compile(ast, options);
|
||||
return new Handlebars.JavaScriptCompiler().compile(environment, options);
|
||||
},
|
||||
invokePartial: function(partial, name, context, helpers, partials) {
|
||||
if(partial === undefined) {
|
||||
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
||||
} else if(partial instanceof Function) {
|
||||
return partial(context, {helpers: helpers, partials: partials});
|
||||
} else {
|
||||
partials[name] = Handlebars.VM.compile(partial);
|
||||
return partials[name](context, {helpers: helpers, partials: partials});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Handlebars.compile = Handlebars.VM.compile;
|
||||
// END(BROWSER)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
var Handlebars = require("handlebars");
|
||||
|
||||
// BEGIN(BROWSER)
|
||||
Handlebars.VM = {
|
||||
programWithDepth: function(fn, helpers, partials, data, $depth) {
|
||||
var args = Array.prototype.slice.call(arguments, 4);
|
||||
|
||||
return function(context, options) {
|
||||
options = options || {};
|
||||
|
||||
options = {
|
||||
helpers: options.helpers || helpers,
|
||||
partials: options.partials || partials,
|
||||
data: options.data || data
|
||||
};
|
||||
|
||||
return fn.apply(this, [context, options].concat(args));
|
||||
};
|
||||
},
|
||||
program: function(fn, helpers, partials, data) {
|
||||
return function(context, options) {
|
||||
options = options || {};
|
||||
|
||||
return fn(context, {
|
||||
helpers: options.helpers || helpers,
|
||||
partials: options.partials || partials,
|
||||
data: options.data || data
|
||||
});
|
||||
};
|
||||
},
|
||||
noop: function() { return ""; },
|
||||
compile: function(string, options) {
|
||||
var ast = Handlebars.parse(string);
|
||||
var environment = new Handlebars.Compiler().compile(ast, options);
|
||||
return new Handlebars.JavaScriptCompiler().compile(environment, options);
|
||||
},
|
||||
invokePartial: function(partial, name, context, helpers, partials) {
|
||||
if(partial === undefined) {
|
||||
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
||||
} else if(partial instanceof Function) {
|
||||
return partial(context, {helpers: helpers, partials: partials});
|
||||
} else {
|
||||
partials[name] = Handlebars.VM.compile(partial);
|
||||
return partials[name](context, {helpers: helpers, partials: partials});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Handlebars.compile = Handlebars.VM.compile;
|
||||
// END(BROWSER)
|
||||
|
||||
+2
-1
@@ -78,7 +78,8 @@ module Handlebars
|
||||
Handlebars::Spec.js_load('lib/handlebars/visitor.js');
|
||||
Handlebars::Spec.js_load('lib/handlebars/printer.js')
|
||||
Handlebars::Spec.js_load('lib/handlebars/utils.js')
|
||||
Handlebars::Spec.js_load('lib/handlebars/compiler.js')
|
||||
Handlebars::Spec.js_load('lib/handlebars/compiler/compiler.js')
|
||||
Handlebars::Spec.js_load('lib/handlebars/vm.js')
|
||||
Handlebars::Spec.js_load('lib/handlebars.js')
|
||||
|
||||
context["Handlebars"]["logger"]["level"] = ENV["DEBUG_JS"] ? context["Handlebars"]["logger"][ENV["DEBUG_JS"]] : 4
|
||||
|
||||
Reference in New Issue
Block a user