UNPKG

@awesome-fe/translate

Version:
76 lines 3.94 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TinyTableRenderer = void 0; var base_tiny_node_renderer_1 = require("./base-tiny-node-renderer"); function renderAttributes(attributes) { return Object.entries(attributes).map(function (_a) { var key = _a[0], value = _a[1]; return "data-".concat(key, "=\"").concat(value, "\""); }).join(' '); } function renderCellSpans(cell) { var colSpan = cell.getColumnSpan(); var rowSpan = cell.getRowSpan(); var result = [colSpan && "data-colspan=".concat(colSpan), rowSpan && "data-rowspan=".concat(rowSpan)].filter(function (it) { return !!it; }).join(' '); return result && "".concat(result, " "); } var TinyTableRenderer = /** @class */ (function (_super) { __extends(TinyTableRenderer, _super); function TinyTableRenderer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.tagName = 'table'; return _this; } TinyTableRenderer.prototype.getContent = function (node) { return [ this.renderCaption(node), this.renderColGroups(node.getColumns()), this.renderHeads(node.getHeadRows()), this.renderBody(node.getBodyRows()), this.renderFoots(node.getFootRows()), ].filter(function (it) { return !!it; }).join(''); }; TinyTableRenderer.prototype.renderCaption = function (node) { return node.getCaption().toString() ? "<caption>".concat(node.getCaption(), "</caption>") : ''; }; TinyTableRenderer.prototype.renderHeads = function (rows) { var _this = this; var result = rows.map(function (row) { return "<tr>".concat(_this.renderRow(row, 'th'), "</tr>"); }).join(''); return rows.length > 0 ? "<thead>".concat(result, "</thead>") : ''; }; TinyTableRenderer.prototype.renderBody = function (rows) { var _this = this; var result = rows.map(function (row) { return "<tr>".concat(_this.renderRow(row, 'td'), "</tr>"); }).join(''); return rows.length > 0 ? "<tbody>".concat(result, "</tbody>") : ''; }; TinyTableRenderer.prototype.renderFoots = function (rows) { var _this = this; var result = rows.map(function (row) { return "<tr>".concat(_this.renderRow(row, 'td'), "</tr>"); }).join(''); return rows.length > 0 ? "<tfoot>".concat(result, "</tfoot>") : ''; }; TinyTableRenderer.prototype.renderColGroups = function (columns) { var result = columns.map(function (column) { return "<col ".concat(renderAttributes(column.getAttributes()), "/>"); }).join(''); return "<colgroup>".concat(result, "</colgroup>"); }; TinyTableRenderer.prototype.renderRow = function (row, tagName) { return row.map(function (cell) { return "<".concat(tagName, " ").concat(renderCellSpans(cell)).concat(renderAttributes(cell.getAttributes()), ">").concat(cell.getContent(), "</").concat(tagName, ">"); }).join(''); }; return TinyTableRenderer; }(base_tiny_node_renderer_1.BaseTinyNodeRenderer)); exports.TinyTableRenderer = TinyTableRenderer; //# sourceMappingURL=tiny-table-renderer.js.map