From c5f54d29f86fb2dcda02753a0becd9c02841c088 Mon Sep 17 00:00:00 2001 From: Paulo Bu Date: Mon, 21 Dec 2015 14:42:07 +0100 Subject: [PATCH] Passes config in the SideBySide constructor and uses it from within the class --- src/html-printer.js | 5 +++-- src/side-by-side-printer.js | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/html-printer.js b/src/html-printer.js index a132d29..f954c25 100644 --- a/src/html-printer.js +++ b/src/html-printer.js @@ -8,7 +8,7 @@ (function() { 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() { } @@ -19,7 +19,8 @@ }; 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(); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index 93a8bd8..b7d226b 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -12,17 +12,18 @@ var utils = require('./utils.js').Utils; 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; return '
\n' + diffFiles.map(function(file) { var diffs; if (file.blocks.length) { - diffs = that.generateSideBySideFileHtml(file, config); + diffs = that.generateSideBySideFileHtml(file); } else { diffs = that.generateEmptyDiff(); } @@ -70,7 +71,7 @@ return Rematch.distance(amod, bmod); }); - SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file, config) { + SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file) { var that = this; var fileHtml = {}; fileHtml.left = ''; @@ -101,7 +102,7 @@ var matches; var insertType; var deleteType; - var doMatching = config.matching === 'lines' || config.matching === 'words'; + var doMatching = that.config.matching === 'lines' || that.config.matching === 'words'; if (doMatching) { matches = matcher(oldLines, newLines); @@ -124,9 +125,9 @@ var oldLine = oldLines[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 += that.generateSingleLineHtml(deleteType, oldLine.oldNumber, @@ -258,6 +259,6 @@ return fileHtml; }; - module.exports.SideBySidePrinter = new SideBySidePrinter(); + module.exports.SideBySidePrinter = SideBySidePrinter; })();