Restructure files to make more sense in a non-CommonJS world.

This commit is contained in:
wycats
2010-11-25 02:49:08 -08:00
parent 38f8ae84fe
commit d97bc591a2
6 changed files with 59 additions and 65 deletions
+14 -23
View File
@@ -1,30 +1,21 @@
var ast = require("handlebars/ast");
var Lexer = require("handlebars/handlebars_lexer").Lexer;
var printer = require("handlebars/printer");
var parser = require("handlebars/parser").parser;
if(exports) {
var Handlebars = {};
parser.yy = {
ProgramNode: ast.ProgramNode,
MustacheNode: ast.MustacheNode,
ContentNode: ast.ContentNode,
IdNode: ast.IdNode,
StringNode: ast.StringNode,
PartialNode: ast.PartialNode,
CommentNode: ast.CommentNode,
BlockNode: ast.BlockNode,
inspect: function(obj) {
var sys = require("sys");
sys.print(sys.inspect(obj) + "\n");
}
Handlebars.AST = require("handlebars/ast").AST;
Handlebars.Lexer = require("handlebars/handlebars_lexer").Lexer;
Handlebars.PrintVisitor = require("handlebars/printer").PrintVisitor;
Handlebars.Parser = require("handlebars/parser").parser;
}
parser.lexer = new Lexer;
exports.parse = function(string) {
return parser.parse(string);
Handlebars.parse = function(string) {
Handlebars.Parser.yy = Handlebars.AST;
Handlebars.Parser.lexer = new Handlebars.Lexer;
return Handlebars.Parser.parse(string);
};
exports.print = function(ast) {
var out = new PrintVisitor().accept(ast);
Handlebars.print = function(ast) {
var out = new Handlebars.PrintVisitor().accept(ast);
require("sys").print(out);
}
if(exports) { exports.Handlebars = Handlebars }
+13 -16
View File
@@ -1,53 +1,50 @@
var ProgramNode = function(statements, inverse) {
if(exports) { var Handlebars = {} }
Handlebars.AST = {};
Handlebars.AST.ProgramNode = function(statements, inverse) {
this.type = "program";
this.statements = statements;
this.inverse = inverse;
};
var MustacheNode = function(params) {
Handlebars.AST.MustacheNode = function(params) {
this.type = "mustache";
this.id = params[0];
this.params = params.slice(1);
};
var PartialNode = function(id) {
Handlebars.AST.PartialNode = function(id) {
this.type = "partial";
this.id = id;
};
var BlockNode = function(mustache, program) {
Handlebars.AST.BlockNode = function(mustache, program) {
this.type = "block";
this.mustache = mustache;
this.program = program;
};
var ContentNode = function(string) {
Handlebars.AST.ContentNode = function(string) {
this.type = "content";
this.string = string;
}
var IdNode = function(id) {
Handlebars.AST.IdNode = function(id) {
this.type = "ID"
this.id = id;
}
StringNode = function(string) {
Handlebars.AST.StringNode = function(string) {
this.type = "STRING";
this.string = string;
}
CommentNode = function(comment) {
Handlebars.AST.CommentNode = function(comment) {
this.type = "comment";
this.comment = comment;
}
if(exports) {
exports.ProgramNode = ProgramNode;
exports.MustacheNode = MustacheNode;
exports.ContentNode = ContentNode;
exports.IdNode = IdNode;
exports.StringNode = StringNode;
exports.PartialNode = PartialNode;
exports.CommentNode = CommentNode;
exports.BlockNode = BlockNode;
exports.AST = Handlebars.AST;
}
+7 -6
View File
@@ -1,13 +1,14 @@
if(require) {
var Lexer = require("handlebars/jison_ext").Lexer
if(exports) {
var Handlebars = {};
Handlebars.Lexer = require("handlebars/jison_ext").Lexer
}
var HandlebarsLexer = function() {
Handlebars.HandlebarsLexer = function() {
this.state = "CONTENT";
};
HandlebarsLexer.prototype = new Lexer;
Handlebars.HandlebarsLexer.prototype = new Handlebars.Lexer;
HandlebarsLexer.prototype.lex = function() {
Handlebars.HandlebarsLexer.prototype.lex = function() {
if(this.input === "") return;
this.setupLex();
@@ -68,4 +69,4 @@ HandlebarsLexer.prototype.lex = function() {
}
};
if(exports) { exports.Lexer = HandlebarsLexer; }
if(exports) { exports.Lexer = Handlebars.HandlebarsLexer; }
+8 -6
View File
@@ -1,6 +1,8 @@
var Lexer = function() {};
if(exports) { var Handlebars = {} }
Lexer.prototype = {
Handlebars.Lexer = function() {};
Handlebars.Lexer.prototype = {
setInput: function(input) {
this.input = input;
this.yylineno = 0;
@@ -44,15 +46,15 @@ Lexer.prototype = {
}
};
var Visitor = function() {};
Handlebars.Visitor = function() {};
Visitor.prototype = {
Handlebars.Visitor.prototype = {
accept: function(object) {
return this[object.type](object);
}
}
if(exports) {
exports.Lexer = Lexer;
exports.Visitor = Visitor;
exports.Lexer = Handlebars.Lexer;
exports.Visitor = Handlebars.Visitor;
}
+16 -13
View File
@@ -1,9 +1,12 @@
if(exports) { var Visitor = require("handlebars/jison_ext").Visitor }
if(exports) {
var Handlebars = {};
Handlebars.Visitor = require("handlebars/jison_ext").Visitor
}
PrintVisitor = function() { this.padding = 0; };
PrintVisitor.prototype = new Visitor;
Handlebars.PrintVisitor = function() { this.padding = 0; };
Handlebars.PrintVisitor.prototype = new Handlebars.Visitor;
PrintVisitor.prototype.pad = function(string, newline) {
Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
var out = "";
for(var i=0,l=this.padding; i<l; i++) {
@@ -16,7 +19,7 @@ PrintVisitor.prototype.pad = function(string, newline) {
return out;
};
PrintVisitor.prototype.program = function(program) {
Handlebars.PrintVisitor.prototype.program = function(program) {
var out = this.pad("PROGRAM:"),
statements = program.statements,
inverse = program.inverse;
@@ -44,7 +47,7 @@ PrintVisitor.prototype.program = function(program) {
return out;
};
PrintVisitor.prototype.block = function(block) {
Handlebars.PrintVisitor.prototype.block = function(block) {
var out = "";
out = out + this.pad("BLOCK:");
@@ -56,7 +59,7 @@ PrintVisitor.prototype.block = function(block) {
return out;
};
PrintVisitor.prototype.mustache = function(mustache) {
Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
var params = mustache.params, paramStrings = [];
for(var i=0, l=params.length; i<l; i++) {
@@ -67,26 +70,26 @@ PrintVisitor.prototype.mustache = function(mustache) {
return this.pad("{{ " + this.accept(mustache.id) + " " + params + "}}");
};
PrintVisitor.prototype.partial = function(partial) {
Handlebars.PrintVisitor.prototype.partial = function(partial) {
return this.pad("{{> " + this.accept(partial.id) + " }}");
};
PrintVisitor.prototype.STRING = function(string) {
Handlebars.PrintVisitor.prototype.STRING = function(string) {
return string.string;
};
PrintVisitor.prototype.ID = function(id) {
Handlebars.PrintVisitor.prototype.ID = function(id) {
return "ID:" + id.id;
};
PrintVisitor.prototype.content = function(content) {
Handlebars.PrintVisitor.prototype.content = function(content) {
return this.pad("CONTENT[ '" + content.string + "' ]");
};
PrintVisitor.prototype.comment = function(comment) {
Handlebars.PrintVisitor.prototype.comment = function(comment) {
return this.pad("{{! '" + comment.comment + "' }}");
}
if(exports) {
exports.PrintVisitor = PrintVisitor;
exports.PrintVisitor = Handlebars.PrintVisitor;
}
+1 -1
View File
@@ -1,6 +1,6 @@
require.paths.push(__dirname + "/lib");
var Handlebars = require("handlebars");
var Handlebars = require("handlebars").Handlebars;
var string = "foo {{ bar baz \"baz\" }}baz{{! foo bar baz }}{{#foo}} bar {{^}} baz {{/foo}}{{> partial }}{{# bar }}part1 {{^}} part2{{> foo }}{{/bar}}zomg"