UNPKG

mobile-cli-lib

Version:
49 lines (48 loc) 1.88 kB
"use strict"; var os_1 = require("os"); var code_entity_1 = require("./code-entity"); var CodePrinter = (function () { function CodePrinter() { } CodePrinter.prototype.composeBlock = function (block, indentSize) { var _this = this; if (indentSize === void 0) { indentSize = 0; } var content = this.getIndentation(indentSize); if (block.opener) { content += block.opener; content += CodePrinter.START_BLOCK_CHAR; content += CodePrinter.NEW_LINE_CHAR; } _.each(block.codeEntities, function (codeEntity) { if (codeEntity.codeEntityType === code_entity_1.CodeEntityType.Line) { content += _this.composeLine(codeEntity, indentSize + 1); } else if (codeEntity.codeEntityType === code_entity_1.CodeEntityType.Block) { content += _this.composeBlock(codeEntity, indentSize + 1); } }); if (block.opener) { content += this.getIndentation(indentSize); content += CodePrinter.END_BLOCK_CHAR; content += block.endingCharacter || ''; } content += CodePrinter.NEW_LINE_CHAR; return content; }; CodePrinter.prototype.getIndentation = function (indentSize) { return Array(indentSize).join(CodePrinter.INDENT_CHAR); }; CodePrinter.prototype.composeLine = function (line, indentSize) { var content = this.getIndentation(indentSize); content += line.content; content += CodePrinter.NEW_LINE_CHAR; return content; }; CodePrinter.INDENT_CHAR = "\t"; CodePrinter.NEW_LINE_CHAR = os_1.EOL; CodePrinter.START_BLOCK_CHAR = "{"; CodePrinter.END_BLOCK_CHAR = "}"; return CodePrinter; }()); exports.CodePrinter = CodePrinter; $injector.register("swaggerCodePrinter", CodePrinter);