Add configuration option to disable the render of templates.

No template would render if the diff shows no difference in its comparison.
This commit is contained in:
Nick Brewer 2019-01-31 17:58:48 -06:00
parent 2512e72f32
commit b43cc1ae91
3 changed files with 22 additions and 2 deletions

View file

@ -19,7 +19,8 @@
matching: 'none',
matchWordsThreshold: 0.25,
matchingMaxComparisons: 2500,
maxLineLengthHighlight: 10000
maxLineLengthHighlight: 10000,
renderNothingWhenEmpty: false,
};
/*

View file

@ -26,6 +26,8 @@
}
LineByLinePrinter.prototype.makeFileDiffHtml = function(file, diffs) {
if (this.config.renderNothingWhenEmpty && file.blocks && !file.blocks.length) return '';
var fileDiffTemplate = hoganUtils.template(baseTemplatesPath, 'file-diff');
var filePathTemplate = hoganUtils.template(genericTemplatesPath, 'file-path');
var fileIconTemplate = hoganUtils.template(iconsBaseTemplatesPath, 'file');

View file

@ -279,6 +279,23 @@ describe('LineByLinePrinter', function() {
' </div>\n' +
'</div>';
assert.equal(expected, fileHtml);
});
it('should return empty when option renderNothingWhenEmpty is true and file blocks not present', function() {
var lineByLinePrinter = new LineByLinePrinter({
renderNothingWhenEmpty: true,
});
var file = {
blocks: [],
};
var diffs = '<span>Random Html</span>';
var fileHtml = lineByLinePrinter.makeFileDiffHtml(file, diffs);
var expected = '';
assert.equal(expected, fileHtml);
});
});
@ -399,7 +416,7 @@ describe('LineByLinePrinter', function() {
isCombined: false
}];
var lineByLinePrinter = new LineByLinePrinter();
var lineByLinePrinter = new LineByLinePrinter({ renderNothingWhenEmpty: false });
var html = lineByLinePrinter.generateLineByLineJsonHtml(exampleJson);
var expected =
'<div class="d2h-wrapper">\n' +