Passes config in the LineByLine constructor and uses it from within the class
This commit is contained in:
parent
4a06df6039
commit
e3f572c075
2 changed files with 12 additions and 10 deletions
|
|
@ -7,14 +7,15 @@
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function(ctx, undefined) {
|
||||||
|
|
||||||
var lineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
|
var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
|
||||||
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
|
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
|
||||||
|
|
||||||
function HtmlPrinter() {
|
function HtmlPrinter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
HtmlPrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
||||||
return lineByLinePrinter.generateLineByLineJsonHtml(diffFiles, config);
|
var lineByLinePrinter = new LineByLinePrinter(config);
|
||||||
|
return lineByLinePrinter.generateLineByLineJsonHtml(diffFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,18 @@
|
||||||
var utils = require('./utils.js').Utils;
|
var utils = require('./utils.js').Utils;
|
||||||
var Rematch = require('./rematch.js').Rematch;
|
var Rematch = require('./rematch.js').Rematch;
|
||||||
|
|
||||||
function LineByLinePrinter() {
|
function LineByLinePrinter(config) {
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
|
||||||
self = this;
|
self = this;
|
||||||
return '<div class="d2h-wrapper">\n' +
|
return '<div class="d2h-wrapper">\n' +
|
||||||
diffFiles.map(function(file) {
|
diffFiles.map(function(file) {
|
||||||
|
|
||||||
var diffs;
|
var diffs;
|
||||||
if (file.blocks.length) {
|
if (file.blocks.length) {
|
||||||
diffs = self.generateFileHtml(file, config);
|
diffs = self.generateFileHtml(file);
|
||||||
} else {
|
} else {
|
||||||
diffs = self.generateEmptyDiff();
|
diffs = self.generateEmptyDiff();
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +60,7 @@
|
||||||
return Rematch.distance(amod, bmod);
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateFileHtml = function(file, config) {
|
LineByLinePrinter.prototype.generateFileHtml = function(file) {
|
||||||
self = this;
|
self = this;
|
||||||
return file.blocks.map(function(block) {
|
return file.blocks.map(function(block) {
|
||||||
|
|
||||||
|
|
@ -76,7 +77,7 @@
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = config.matching === "lines" || config.matching === "words";
|
var doMatching = self.config.matching === "lines" || self.config.matching === "words";
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
||||||
|
|
@ -99,8 +100,8 @@
|
||||||
oldLine = oldLines[j];
|
oldLine = oldLines[j];
|
||||||
newLine = newLines[j];
|
newLine = newLines[j];
|
||||||
|
|
||||||
config.isCombined = file.isCombined;
|
self.config.isCombined = file.isCombined;
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, self.config);
|
||||||
|
|
||||||
processedOldLines +=
|
processedOldLines +=
|
||||||
self.generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
self.generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||||
|
|
@ -198,6 +199,6 @@
|
||||||
'</tr>\n';
|
'</tr>\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports['LineByLinePrinter'] = new LineByLinePrinter();
|
module.exports['LineByLinePrinter'] = LineByLinePrinter;
|
||||||
|
|
||||||
})(this);
|
})(this);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue