diff options
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | Rakefile | 4 | ||||
-rw-r--r-- | lib/handlebars.js | 22 | ||||
-rw-r--r-- | lib/handlebars/ast.js | 6 | ||||
-rw-r--r-- | lib/handlebars/base.js (renamed from lib/handlebars/compiler.js) | 25 | ||||
-rw-r--r-- | lib/handlebars/debug.js | 4 | ||||
-rw-r--r-- | lib/handlebars/printer.js | 4 | ||||
-rw-r--r-- | lib/handlebars/runtime.js | 14 | ||||
-rw-r--r-- | lib/handlebars/utils.js | 5 | ||||
-rw-r--r-- | lib/handlebars/visitor.js | 3 | ||||
-rw-r--r-- | lib/handlebars/vm.js | 9 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/tokenizer_spec.rb | 2 | ||||
-rw-r--r-- | src/handlebars.l | 1 |
14 files changed, 39 insertions, 65 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index a337012..d500323 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,3 @@ PLATFORMS DEPENDENCIES rspec therubyracer (>= 0.8.0.pre3) - -METADATA - version: 1.1.pre @@ -20,11 +20,11 @@ def remove_exports(string) match ? match[1] : string end -minimal_deps = %w(parser compiler ast visitor runtime utils vm).map do |file| +minimal_deps = %w(parser base ast visitor runtime utils vm).map do |file| "lib/handlebars/#{file}.js" end -debug_deps = %w(parser compiler ast visitor printer runtime utils vm).map do |file| +debug_deps = %w(parser base ast visitor printer runtime utils vm).map do |file| "lib/handlebars/#{file}.js" end diff --git a/lib/handlebars.js b/lib/handlebars.js index c2f88b3..1f85892 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -1,18 +1,16 @@ -var Handlebars = require("handlebars/compiler").Handlebars; +var Handlebars = require("handlebars/base"); +module.exports = Handlebars; -Handlebars.AST = require("handlebars/ast").AST; -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; +require("handlebars/utils"); + +require("handlebars/ast"); +require("handlebars/printer"); +require("handlebars/visitor"); + +require("handlebars/runtime"); +require("handlebars/vm"); // BEGIN(BROWSER) // END(BROWSER) -exports.Handlebars = Handlebars; diff --git a/lib/handlebars/ast.js b/lib/handlebars/ast.js index 837e758..8966fd6 100644 --- a/lib/handlebars/ast.js +++ b/lib/handlebars/ast.js @@ -1,5 +1,4 @@ -var Handlebars = {}; -Handlebars.Exception = require("handlebars/utils").Exception; +var Handlebars = require("handlebars"); // BEGIN(BROWSER) (function() { @@ -69,7 +68,7 @@ Handlebars.Exception = require("handlebars/utils").Exception; this.parts = dig; this.depth = depth; - this.isSimple = (dig.length === 1) && (depth === 0) + this.isSimple = (dig.length === 1) && (depth === 0); }; Handlebars.AST.StringNode = function(string) { @@ -85,4 +84,3 @@ Handlebars.Exception = require("handlebars/utils").Exception; })(); // END(BROWSER) -exports.AST = Handlebars.AST; diff --git a/lib/handlebars/compiler.js b/lib/handlebars/base.js index d1e4445..c6b2f8e 100644 --- a/lib/handlebars/compiler.js +++ b/lib/handlebars/base.js @@ -18,15 +18,8 @@ Handlebars.compile = function(string) { var ast = Handlebars.parse(string); return function(context, helpers, partials) { - var helpers, partials; - - if(!helpers) { - helpers = Handlebars.helpers; - } - - if(!partials) { - partials = Handlebars.partials; - } + helpers = helpers || Handlebars.helpers; + partials = partials || Handlebars.partials; var internalContext = new Handlebars.Context(context, helpers, partials); var runtime = new Handlebars.Runtime(internalContext); @@ -71,10 +64,10 @@ Handlebars.registerHelper('blockHelperMissing', function(context, fn, inverse) { } return ret; } else { - return fn(context); - } + return fn(context); + } }, function(context, fn) { - return fn(context) + return fn(context); }); Handlebars.registerHelper('each', function(context, fn, inverse) { @@ -98,6 +91,10 @@ Handlebars.registerHelper('if', function(context, fn, inverse) { } }); +Handlebars.registerHelper('unless', function(context, fn, inverse) { + Handlebars.helpers['if'].call(this, context, inverse, fn); +}); + Handlebars.registerHelper('with', function(context, fn) { return fn(context); }); @@ -106,11 +103,11 @@ Handlebars.logger = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3, // override in the host environment - log: function(level, str) {}, + log: function(level, str) {} } Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); }; // END(BROWSER) -exports.Handlebars = Handlebars; +module.exports = Handlebars; diff --git a/lib/handlebars/debug.js b/lib/handlebars/debug.js index 90425d5..c9c73ca 100644 --- a/lib/handlebars/debug.js +++ b/lib/handlebars/debug.js @@ -1,3 +1,6 @@ +var Handlebars = require("handlebars"); + +// BEGIN(BROWSER) (function() { var classes = ["Lexer", "PrintVisitor", "Context", "Runtime", "Exception"]; var prop; @@ -23,3 +26,4 @@ Handlebars.print.displayName = "Handlebars.print"; Handlebars.compile.displayName = "Handlebars.compile"; })(); +// END(BROWSER) diff --git a/lib/handlebars/printer.js b/lib/handlebars/printer.js index 2f663e3..549e56b 100644 --- a/lib/handlebars/printer.js +++ b/lib/handlebars/printer.js @@ -1,5 +1,5 @@ -var Handlebars = {}; -Handlebars.Visitor = require("handlebars/visitor").Visitor; +var Handlebars = require("handlebars"); +require("handlebars/visitor"); // BEGIN(BROWSER) Handlebars.PrintVisitor = function() { this.padding = 0; }; diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index ae2a270..6fa7f40 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -2,17 +2,7 @@ var inspect = function(obj) { require("sys").print(require("sys").inspect(obj) + "\n"); }; -var Handlebars = {}; - -Handlebars.AST = require("handlebars/ast").AST; -Handlebars.Visitor = require("handlebars/visitor").Visitor; -Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor; -Handlebars.Parser = require("handlebars/parser").parser; -Handlebars.Runtime = require("handlebars/runtime").Runtime; -Handlebars.Utils = require("handlebars/utils").Utils; -Handlebars.SafeString = require("handlebars/utils").SafeString; -Handlebars.Exception = require("handlebars/utils").Exception; -Handlebars.parse = require("handlebars/compiler").Handlebars.parse; +var Handlebars = require("handlebars"); // BEGIN(BROWSER) // A Context wraps data, and makes it possible to extract a @@ -275,5 +265,3 @@ Handlebars.Runtime.prototype = { }; // END(BROWSER) -exports.Runtime = Handlebars.Runtime; -exports.Context = Handlebars.Context; diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index d579c0b..409a489 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -1,4 +1,4 @@ -var Handlebars = {}; +var Handlebars = require("handlebars"); // BEGIN(BROWSER) Handlebars.Exception = function(message) { @@ -56,6 +56,3 @@ Handlebars.SafeString.prototype.toString = function() { })(); // END(BROWSER) -exports.Utils = Handlebars.Utils; -exports.SafeString = Handlebars.SafeString; -exports.Exception = Handlebars.Exception; diff --git a/lib/handlebars/visitor.js b/lib/handlebars/visitor.js index 04f025d..a713bcc 100644 --- a/lib/handlebars/visitor.js +++ b/lib/handlebars/visitor.js @@ -1,4 +1,4 @@ -var Handlebars = {}; +var Handlebars = require("handlebars"); // BEGIN(BROWSER) @@ -11,4 +11,3 @@ Handlebars.Visitor.prototype = { }; // END(BROWSER) -exports.Visitor = Handlebars.Visitor; diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js index cf821bc..ab618a1 100644 --- a/lib/handlebars/vm.js +++ b/lib/handlebars/vm.js @@ -1,8 +1,4 @@ -var Handlebars = {}; -Handlebars.Utils = require("handlebars/utils").Utils; -Handlebars.parse = require("handlebars/compiler").Handlebars.parse; -Handlebars.logger = require("handlebars/compiler").Handlebars.logger; -Handlebars.log = require("handlebars/compiler").Handlebars.log; +var Handlebars = require("handlebars"); // BEGIN(BROWSER) Handlebars.Compiler = function() {}; @@ -629,6 +625,3 @@ Handlebars.VM = { }; // END(BROWSER) -exports.Compiler = Handlebars.Compiler; -exports.JavaScriptCompiler = Handlebars.JavaScriptCompiler; -exports.VM = Handlebars.VM; diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c23c41..0abfe20 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,7 +73,7 @@ module Handlebars end Handlebars::Spec.js_load('lib/handlebars/parser.js') - Handlebars::Spec.js_load('lib/handlebars/compiler.js'); + Handlebars::Spec.js_load('lib/handlebars/base.js'); Handlebars::Spec.js_load('lib/handlebars/ast.js'); Handlebars::Spec.js_load('lib/handlebars/visitor.js'); Handlebars::Spec.js_load('lib/handlebars/printer.js') diff --git a/spec/tokenizer_spec.rb b/spec/tokenizer_spec.rb index e2f84ce..fba7c31 100644 --- a/spec/tokenizer_spec.rb +++ b/spec/tokenizer_spec.rb @@ -95,6 +95,8 @@ describe "Tokenizer" do it "tokenizes inverse sections as 'OPEN_INVERSE CLOSE'" do tokenize("{{^}}").should match_tokens(%w(OPEN_INVERSE CLOSE)) + tokenize("{{else}}").should match_tokens(%w(OPEN_INVERSE CLOSE)) + tokenize("{{ else }}").should match_tokens(%w(OPEN_INVERSE CLOSE)) end it "tokenizes inverse sections with ID as 'OPEN_INVERSE ID CLOSE'" do diff --git a/src/handlebars.l b/src/handlebars.l index e29864d..d6b354f 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -10,6 +10,7 @@ <mu>"{{#" { return 'OPEN_BLOCK'; } <mu>"{{/" { return 'OPEN_ENDBLOCK'; } <mu>"{{^" { return 'OPEN_INVERSE'; } +<mu>"{{"\s*"else" { return 'OPEN_INVERSE'; } <mu>"{{{" { return 'OPEN_UNESCAPED'; } <mu>"{{&" { return 'OPEN_UNESCAPED'; } <mu>"{{!".*?"}}" { yytext = yytext.substr(3,yyleng-5); this.begin("INITIAL"); return 'COMMENT'; } |