Code coverage report for dist/cjs/handlebars/compiler/printer.js

Statements: 100% (84 / 84)      Branches: 100% (16 / 16)      Functions: 100% (17 / 17)      Lines: 100% (80 / 80)      Ignored: none     

All files » dist/cjs/handlebars/compiler/ » printer.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141  1   1 48     1 48     1   1 89   89 50     89 89     1 67       67 59     67   67     1 11   11 11 11 11 9 9 9 9   11 10 10 10 10 10 10   11   11     1 40   40 11     40   40   40     1 40     1 5 5 2   5 2   5     1 14 14   14 23 23 23     14     1 7     1 3     1 6     1 60 60 1   59       1 5     1 4     1 12     1 2  
"use strict";
var Visitor = require("./visitor")["default"];
 
function print(ast) {
  return new PrintVisitor().accept(ast);
}
 
exports.print = print;function PrintVisitor() {
  this.padding = 0;
}
 
exports.PrintVisitor = PrintVisitor;PrintVisitor.prototype = new Visitor();
 
PrintVisitor.prototype.pad = function(string) {
  var out = "";
 
  for(var i=0,l=this.padding; i<l; i++) {
    out = out + "  ";
  }
 
  out = out + string + "\n";
  return out;
};
 
PrintVisitor.prototype.program = function(program) {
  var out = "",
      statements = program.statements,
      i, l;
 
  for(i=0, l=statements.length; i<l; i++) {
    out = out + this.accept(statements[i]);
  }
 
  this.padding--;
 
  return out;
};
 
PrintVisitor.prototype.block = function(block) {
  var out = "";
 
  out = out + this.pad("BLOCK:");
  this.padding++;
  out = out + this.accept(block.mustache);
  if (block.program) {
    out = out + this.pad("PROGRAM:");
    this.padding++;
    out = out + this.accept(block.program);
    this.padding--;
  }
  if (block.inverse) {
    if (block.program) { this.padding++; }
    out = out + this.pad("{{^}}");
    this.padding++;
    out = out + this.accept(block.inverse);
    this.padding--;
    if (block.program) { this.padding--; }
  }
  this.padding--;
 
  return out;
};
 
PrintVisitor.prototype.sexpr = function(sexpr) {
  var params = sexpr.params, paramStrings = [], hash;
 
  for(var i=0, l=params.length; i<l; i++) {
    paramStrings.push(this.accept(params[i]));
  }
 
  params = "[" + paramStrings.join(", ") + "]";
 
  hash = sexpr.hash ? " " + this.accept(sexpr.hash) : "";
 
  return this.accept(sexpr.id) + " " + params + hash;
};
 
PrintVisitor.prototype.mustache = function(mustache) {
  return this.pad("{{ " + this.accept(mustache.sexpr) + " }}");
};
 
PrintVisitor.prototype.partial = function(partial) {
  var content = this.accept(partial.partialName);
  if(partial.context) {
    content += " " + this.accept(partial.context);
  }
  if (partial.hash) {
    content += " " + this.accept(partial.hash);
  }
  return this.pad("{{> " + content + " }}");
};
 
PrintVisitor.prototype.hash = function(hash) {
  var pairs = hash.pairs;
  var joinedPairs = [], left, right;
 
  for(var i=0, l=pairs.length; i<l; i++) {
    left = pairs[i][0];
    right = this.accept(pairs[i][1]);
    joinedPairs.push( left + "=" + right );
  }
 
  return "HASH{" + joinedPairs.join(", ") + "}";
};
 
PrintVisitor.prototype.STRING = function(string) {
  return '"' + string.string + '"';
};
 
PrintVisitor.prototype.NUMBER = function(number) {
  return "NUMBER{" + number.number + "}";
};
 
PrintVisitor.prototype.BOOLEAN = function(bool) {
  return "BOOLEAN{" + bool.bool + "}";
};
 
PrintVisitor.prototype.ID = function(id) {
  var path = id.parts.join("/");
  if(id.parts.length > 1) {
    return "PATH:" + path;
  } else {
    return "ID:" + path;
  }
};
 
PrintVisitor.prototype.PARTIAL_NAME = function(partialName) {
    return "PARTIAL:" + partialName.name;
};
 
PrintVisitor.prototype.DATA = function(data) {
  return "@" + this.accept(data.id);
};
 
PrintVisitor.prototype.content = function(content) {
  return this.pad("CONTENT[ '" + content.string + "' ]");
};
 
PrintVisitor.prototype.comment = function(comment) {
  return this.pad("{{! '" + comment.comment + "' }}");
};