Refactors HTML code into their own methods

This commit is contained in:
Paulo Bu 2015-12-27 11:08:50 +01:00
parent 97eafcd2f7
commit a37176cc26

View file

@ -16,18 +16,7 @@
this.config = config; this.config = config;
} }
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) { LineByLinePrinter.prototype.makeFileDiffHtml = function(file, diffs) {
var that = this;
return '<div class="d2h-wrapper">\n' +
diffFiles.map(function(file) {
var diffs;
if (file.blocks.length) {
diffs = that._generateFileHtml(file);
} else {
diffs = that._generateEmptyDiff();
}
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' + return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
' <div class="d2h-file-header">\n' + ' <div class="d2h-file-header">\n' +
' <div class="d2h-file-stats">\n' + ' <div class="d2h-file-stats">\n' +
@ -50,8 +39,21 @@
' </div>\n' + ' </div>\n' +
' </div>\n' + ' </div>\n' +
' </div>\n'; ' </div>\n';
}).join('\n') + };
'</div>\n';
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
var that = this;
var htmlDiffs = diffFiles.map(function(file) {
var diffs;
if (file.blocks.length) {
diffs = that._generateFileHtml(file);
} else {
diffs = that._generateEmptyDiff();
}
return that.makeFileDiffHtml(file, diffs);
});
return '<div class="d2h-wrapper">\n' + htmlDiffs.join('\n') + '</div>\n';
}; };
var matcher = Rematch.rematch(function(a, b) { var matcher = Rematch.rematch(function(a, b) {
@ -61,17 +63,20 @@
return Rematch.distance(amod, bmod); return Rematch.distance(amod, bmod);
}); });
LineByLinePrinter.prototype._generateFileHtml = function(file) { LineByLinePrinter.prototype.makeColumnLineNumberHtml = function(block) {
var that = this; return '<tr>\n' +
return file.blocks.map(function(block) {
var lines = '<tr>\n' +
' <td class="d2h-code-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' + ' <td class="d2h-code-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' + ' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' + utils.escape(block.header) + '</div>' + ' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' + utils.escape(block.header) + '</div>' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
};
LineByLinePrinter.prototype._generateFileHtml = function(file) {
var that = this;
return file.blocks.map(function(block) {
var lines = that.makeColumnLineNumberHtml(block);
var oldLines = []; var oldLines = [];
var newLines = []; var newLines = [];
@ -172,6 +177,18 @@
return lines; return lines;
}; };
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, htmlPrefix, htmlContent) {
return '<tr>\n' +
' <td class="d2h-code-linenumber ' + type + '">' +
' <div class="line-num1">' + utils.valueOrEmpty(oldNumber) + '</div>' +
' <div class="line-num2">' + utils.valueOrEmpty(newNumber) + '</div>' +
' </td>\n' +
' <td class="' + type + '">' +
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
' </td>\n' +
'</tr>\n';
};
LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) { LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) {
var htmlPrefix = ''; var htmlPrefix = '';
if (prefix) { if (prefix) {
@ -183,15 +200,7 @@
htmlContent = '<span class="d2h-code-line-ctn">' + content + '</span>'; htmlContent = '<span class="d2h-code-line-ctn">' + content + '</span>';
} }
return '<tr>\n' + return this.makeLineHtml(type, oldNumber, newNumber, htmlPrefix, htmlContent);
' <td class="d2h-code-linenumber ' + type + '">' +
' <div class="line-num1">' + utils.valueOrEmpty(oldNumber) + '</div>' +
' <div class="line-num2">' + utils.valueOrEmpty(newNumber) + '</div>' +
' </td>\n' +
' <td class="' + type + '">' +
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
' </td>\n' +
'</tr>\n';
}; };
LineByLinePrinter.prototype._generateEmptyDiff = function() { LineByLinePrinter.prototype._generateEmptyDiff = function() {