Passes config in the SideBySide constructor and uses it from within the class
This commit is contained in:
parent
a4cf385a7d
commit
c5f54d29f8
2 changed files with 12 additions and 10 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
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() {
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) {
|
HtmlPrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) {
|
||||||
return sideBySidePrinter.generateSideBySideJsonHtml(diffFiles, config);
|
var sideBySidePrinter = new SideBySidePrinter(config);
|
||||||
|
return sideBySidePrinter.generateSideBySideJsonHtml(diffFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.HtmlPrinter = new HtmlPrinter();
|
module.exports.HtmlPrinter = new HtmlPrinter();
|
||||||
|
|
|
||||||
|
|
@ -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 SideBySidePrinter() {
|
function SideBySidePrinter(config) {
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) {
|
SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles) {
|
||||||
var that = this;
|
var that = 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 = that.generateSideBySideFileHtml(file, config);
|
diffs = that.generateSideBySideFileHtml(file);
|
||||||
} else {
|
} else {
|
||||||
diffs = that.generateEmptyDiff();
|
diffs = that.generateEmptyDiff();
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +71,7 @@
|
||||||
return Rematch.distance(amod, bmod);
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file, config) {
|
SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var fileHtml = {};
|
var fileHtml = {};
|
||||||
fileHtml.left = '';
|
fileHtml.left = '';
|
||||||
|
|
@ -101,7 +102,7 @@
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = config.matching === 'lines' || config.matching === 'words';
|
var doMatching = that.config.matching === 'lines' || that.config.matching === 'words';
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
|
|
@ -124,9 +125,9 @@
|
||||||
var oldLine = oldLines[j];
|
var oldLine = oldLines[j];
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[j];
|
||||||
|
|
||||||
config.isCombined = file.isCombined;
|
that.config.isCombined = file.isCombined;
|
||||||
|
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
fileHtml.left +=
|
fileHtml.left +=
|
||||||
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
||||||
|
|
@ -258,6 +259,6 @@
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.SideBySidePrinter = new SideBySidePrinter();
|
module.exports.SideBySidePrinter = SideBySidePrinter;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue