diff options
author | kpdecker <kpdecker@gmail.com> | 2011-07-30 10:11:13 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2011-07-30 10:11:13 -0500 |
commit | f2dccb753f16d4d8e6e8c93c130156258f7c3ab8 (patch) | |
tree | 91d8caccb0d14142989c5e1e2ca450f39e176e05 | |
parent | 471f3b9748fe600387d226d4aaea09c95ddca1af (diff) | |
download | handlebars.js-f2dccb753f16d4d8e6e8c93c130156258f7c3ab8.zip handlebars.js-f2dccb753f16d4d8e6e8c93c130156258f7c3ab8.tar.gz handlebars.js-f2dccb753f16d4d8e6e8c93c130156258f7c3ab8.tar.bz2 |
Break compiler and vm logic into separate files.
-rw-r--r-- | Rakefile | 4 | ||||
-rw-r--r-- | lib/handlebars/compiler/compiler.js (renamed from lib/handlebars/compiler.js) | 46 | ||||
-rw-r--r-- | lib/handlebars/vm.js | 51 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 |
4 files changed, 55 insertions, 49 deletions
@@ -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 diff --git a/lib/handlebars/compiler.js b/lib/handlebars/compiler/compiler.js index 641f31a..fbac73b 100644 --- a/lib/handlebars/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -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) diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js new file mode 100644 index 0000000..0b4c448 --- /dev/null +++ b/lib/handlebars/vm.js @@ -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) + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3c89ef..7a6dbe9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 |