|
|
|
@@ -1,15 +1,13 @@
|
|
|
|
|
exports.attach = function(Handlebars) {
|
|
|
|
|
import Visitor from "handlebars/compiler/visitor";
|
|
|
|
|
|
|
|
|
|
// BEGIN(BROWSER)
|
|
|
|
|
|
|
|
|
|
Handlebars.print = function(ast) {
|
|
|
|
|
return new Handlebars.PrintVisitor().accept(ast);
|
|
|
|
|
export print = function(ast) {
|
|
|
|
|
return new PrintVisitor().accept(ast);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Handlebars.PrintVisitor = function() { this.padding = 0; };
|
|
|
|
|
Handlebars.PrintVisitor.prototype = new Handlebars.Visitor();
|
|
|
|
|
export function PrintVisitor() { this.padding = 0; };
|
|
|
|
|
PrintVisitor.prototype = new Handlebars.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 +20,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 +35,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:");
|
|
|
|
@@ -76,13 +74,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 +93,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 +114,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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|