Skip to content

Commit 96ccbe4

Browse files
committed
Merge pull request #51 from bem/fixes
Fixes
2 parents d358d63 + 13ce98d commit 96ccbe4

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

lib/cli.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var path = require('path'),
22
vow = require('vow'),
33
vfs = require('vow-fs'),
44
HtmlDiffer = require('./index').HtmlDiffer,
5-
diffLogger = require('./diff-logger');
5+
diffLogger = require('./diff-logger'),
6+
utils = require('./utils');
67

78
module.exports = require('coa').Cmd()
89
.name(process.argv[1])
@@ -26,6 +27,14 @@ module.exports = require('coa').Cmd()
2627
.title('Path to configuration JSON-file')
2728
.long('config')
2829
.end()
30+
.opt()
31+
.name('charsAroundDiff')
32+
.title('Number of characters around diff')
33+
.long('chars-around-diff')
34+
.val(function(val) {
35+
return parseInt(val);
36+
})
37+
.end()
2938
.arg()
3039
.name('path1')
3140
.title('Path to the 1-st html-file')
@@ -44,11 +53,13 @@ module.exports = require('coa').Cmd()
4453
]).spread(function (html1, html2, config) {
4554
config = config ? JSON.parse(config) : {};
4655

47-
var diffOpts = { ignoreHtmlAttrs: config.ignoreHtmlAttrs || [], compareHtmlAttrsAsJSON: config.compareHtmlAttrsAsJSON },
48-
logOpts = { showCharacters: config.showCharacters || 20 };
56+
var options = utils.defaults(config),
57+
loggerOptions = {
58+
charsAroundDiff: opts.charsAroundDiff || 20
59+
};
4960

50-
htmlDiffer = new HtmlDiffer(diffOpts),
51-
diffLogger.log(htmlDiffer.diffHtml(html1, html2), logOpts);
61+
htmlDiffer = new HtmlDiffer(options),
62+
diffLogger.log(htmlDiffer.diffHtml(html1, html2), loggerOptions);
5263
});
5364
})
5465
.run(process.argv.slice(2));

lib/diff-logger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function getDiffText(diff, options) {
2020
var charsAroundDiff = options.charsAroundDiff,
2121
output = '';
2222

23-
if (charsAroundDiff > 0) {
23+
if (charsAroundDiff < 0) {
2424
charsAroundDiff = 20;
2525
}
2626

@@ -35,7 +35,7 @@ function getDiffText(diff, options) {
3535
if (part.removed) color = 'red';
3636

3737
if (color !== 'grey') {
38-
output += (!index ? '\n' : '') + partValue[color];
38+
output += (!index ? '\n' : '') + partValue[color];
3939

4040
return;
4141
}

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
142142
console.warn('WARNING! The third param of "diffHtml" method is deprecated!');
143143
}
144144

145+
options = _.defaults(this.options, options);
146+
145147
var htmlDiffer = new HtmlDiff(options);
146148

147149
return htmlDiffer.diff(html1, html2);

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports.parseAttr = function(val, isClick) {
3838
};
3939

4040
/**
41-
* Sorts the gieven CSS class attribute
41+
* Sorts the given CSS class attribute
4242
* @param {String} cssClasses
4343
* @returns {String}
4444
*/

0 commit comments

Comments
 (0)