Nouvelle compilation des scripts en JS (suite).
This commit is contained in:
parent
858162aaad
commit
9c19d07488
48
src/build/freeDatas2HTMLRender.js
Normal file
48
src/build/freeDatas2HTMLRender.js
Normal file
@ -0,0 +1,48 @@
|
||||
var errors = require("./errors.js");
|
||||
var Render = (function () {
|
||||
function Render(converter, settings) {
|
||||
if (settings === void 0) { settings = Render.defaultSettings; }
|
||||
this._converter = converter;
|
||||
this.settings = settings;
|
||||
}
|
||||
Render.prototype.rend2HTML = function (datas) {
|
||||
if (this._converter.parseMetas === undefined || this._converter.parseMetas.fields === undefined)
|
||||
throw new Error(errors.renderNeedDatas);
|
||||
else {
|
||||
var datasHTML = this.settings.allBegining;
|
||||
if (this.settings.fieldsBegining !== undefined && this.settings.fieldDisplaying !== undefined && this.settings.fieldsEnding !== undefined) {
|
||||
datasHTML += this.settings.fieldsBegining;
|
||||
for (var i in this._converter.parseMetas.fields)
|
||||
datasHTML += this.settings.fieldDisplaying.replace("#FIELDNAME", this._converter.parseMetas.fields[Number(i)]);
|
||||
datasHTML += this.settings.fieldsEnding;
|
||||
}
|
||||
datasHTML += this.settings.linesBegining;
|
||||
for (var row in datas) {
|
||||
datasHTML += this.settings.lineBegining;
|
||||
for (var field in datas[row]) {
|
||||
if (this._converter.parseMetas.fields.indexOf(field) !== -1)
|
||||
datasHTML += this.settings.dataDisplaying.replace("#VALUE", datas[row][field]).replace("#FIELDNAME", field);
|
||||
else
|
||||
console.log(errors.renderUnknownField + field);
|
||||
}
|
||||
datasHTML += this.settings.lineEnding;
|
||||
}
|
||||
datasHTML += this.settings.linesEnding + this.settings.allEnding;
|
||||
return datasHTML;
|
||||
}
|
||||
};
|
||||
Render.defaultSettings = {
|
||||
allBegining: "<table>",
|
||||
allEnding: "</table>",
|
||||
fieldsBegining: "<thead><tr>",
|
||||
fieldsEnding: "</tr></thead>",
|
||||
fieldDisplaying: "<th>#FIELDNAME</th>",
|
||||
linesBegining: "<tbody>",
|
||||
linesEnding: "</tbody>",
|
||||
lineBegining: "<tr>",
|
||||
lineEnding: "</tr>",
|
||||
dataDisplaying: "<td>#VALUE</td>",
|
||||
};
|
||||
return Render;
|
||||
}());
|
||||
export { Render };
|
Loading…
Reference in New Issue
Block a user