summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/printer.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/printer.js')
-rw-r--r--lib/handlebars/compiler/printer.js47
1 files changed, 22 insertions, 25 deletions
diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js
index d9eb7a5..a35cdf4 100644
--- a/lib/handlebars/compiler/printer.js
+++ b/lib/handlebars/compiler/printer.js
@@ -1,15 +1,16 @@
-exports.attach = function(Handlebars) {
+import Visitor from "./visitor";
-// BEGIN(BROWSER)
+export function print(ast) {
+ return new PrintVisitor().accept(ast);
+}
-Handlebars.print = function(ast) {
- return new Handlebars.PrintVisitor().accept(ast);
-};
+export function PrintVisitor() {
+ this.padding = 0;
+}
-Handlebars.PrintVisitor = function() { this.padding = 0; };
-Handlebars.PrintVisitor.prototype = new Handlebars.Visitor();
+PrintVisitor.prototype = new Visitor();
-Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
+PrintVisitor.prototype.pad = function(string, newline) {
var out = "";
for(var i=0,l=this.padding; i<l; i++) {
@@ -22,7 +23,7 @@ Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
return out;
};
-Handlebars.PrintVisitor.prototype.program = function(program) {
+PrintVisitor.prototype.program = function(program) {
var out = "",
statements = program.statements,
inverse = program.inverse,
@@ -37,7 +38,7 @@ Handlebars.PrintVisitor.prototype.program = function(program) {
return out;
};
-Handlebars.PrintVisitor.prototype.block = function(block) {
+PrintVisitor.prototype.block = function(block) {
var out = "";
out = out + this.pad("BLOCK:");
@@ -62,7 +63,7 @@ Handlebars.PrintVisitor.prototype.block = function(block) {
return out;
};
-Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
+PrintVisitor.prototype.mustache = function(mustache) {
var params = mustache.params, paramStrings = [], hash;
for(var i=0, l=params.length; i<l; i++) {
@@ -76,13 +77,13 @@ Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
return this.pad("{{ " + this.accept(mustache.id) + " " + params + hash + " }}");
};
-Handlebars.PrintVisitor.prototype.partial = function(partial) {
+PrintVisitor.prototype.partial = function(partial) {
var content = this.accept(partial.partialName);
if(partial.context) { content = content + " " + this.accept(partial.context); }
return this.pad("{{> " + content + " }}");
};
-Handlebars.PrintVisitor.prototype.hash = function(hash) {
+PrintVisitor.prototype.hash = function(hash) {
var pairs = hash.pairs;
var joinedPairs = [], left, right;
@@ -95,19 +96,19 @@ Handlebars.PrintVisitor.prototype.hash = function(hash) {
return "HASH{" + joinedPairs.join(", ") + "}";
};
-Handlebars.PrintVisitor.prototype.STRING = function(string) {
+PrintVisitor.prototype.STRING = function(string) {
return '"' + string.string + '"';
};
-Handlebars.PrintVisitor.prototype.INTEGER = function(integer) {
+PrintVisitor.prototype.INTEGER = function(integer) {
return "INTEGER{" + integer.integer + "}";
};
-Handlebars.PrintVisitor.prototype.BOOLEAN = function(bool) {
+PrintVisitor.prototype.BOOLEAN = function(bool) {
return "BOOLEAN{" + bool.bool + "}";
};
-Handlebars.PrintVisitor.prototype.ID = function(id) {
+PrintVisitor.prototype.ID = function(id) {
var path = id.parts.join("/");
if(id.parts.length > 1) {
return "PATH:" + path;
@@ -116,23 +117,19 @@ Handlebars.PrintVisitor.prototype.ID = function(id) {
}
};
-Handlebars.PrintVisitor.prototype.PARTIAL_NAME = function(partialName) {
+PrintVisitor.prototype.PARTIAL_NAME = function(partialName) {
return "PARTIAL:" + partialName.name;
};
-Handlebars.PrintVisitor.prototype.DATA = function(data) {
+PrintVisitor.prototype.DATA = function(data) {
return "@" + this.accept(data.id);
};
-Handlebars.PrintVisitor.prototype.content = function(content) {
+PrintVisitor.prototype.content = function(content) {
return this.pad("CONTENT[ '" + content.string + "' ]");
};
-Handlebars.PrintVisitor.prototype.comment = function(comment) {
+PrintVisitor.prototype.comment = function(comment) {
return this.pad("{{! '" + comment.comment + "' }}");
};
-// END(BROWSER)
-
-return Handlebars;
-};