From 71648c68ba1a0863e899a196d03290d279bd27f3 Mon Sep 17 00:00:00 2001 From: Evgeniy Gavryushin Date: Tue, 22 Jul 2014 15:29:33 +0400 Subject: [PATCH 1/3] Set a default value of the option 'charsAroundDiff' to 40 --- lib/cli.js | 5 +++-- lib/diff-logger.js | 8 ++++---- lib/index.js | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index ad8afcf5..fbbad7b4 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -27,8 +27,9 @@ module.exports = require('coa').Cmd() .end() .opt() .name('charsAroundDiff') - .title('The number of characters around the diff') + .title('The number of characters around the diff (default: 40)') .long('chars-around-diff') + .def(40) .val(function(val) { return parseInt(val); }) @@ -53,7 +54,7 @@ module.exports = require('coa').Cmd() var options = utils.defaults(config), loggerOptions = { - charsAroundDiff: opts.charsAroundDiff || 20 + charsAroundDiff: opts.charsAroundDiff }; htmlDiffer = new HtmlDiffer(options), diff --git a/lib/diff-logger.js b/lib/diff-logger.js index f97235f5..976c4afe 100644 --- a/lib/diff-logger.js +++ b/lib/diff-logger.js @@ -4,12 +4,12 @@ require('colors'); * Returns readable diff text * @param {Object[]} diff * @param {Object} [options] - * @param {Number} [options.charsAroundDiff=20] + * @param {Number} [options.charsAroundDiff=40] * @returns {String} */ function getDiffText(diff, options) { options = options || { - charsAroundDiff: 20 + charsAroundDiff: 40 }; if (options.showCharacters) { @@ -21,7 +21,7 @@ function getDiffText(diff, options) { output = ''; if (charsAroundDiff < 0) { - charsAroundDiff = 20; + charsAroundDiff = 40; } if (diff.length === 1 && !diff[0].added && !diff[0].removed) return output; @@ -58,7 +58,7 @@ function getDiffText(diff, options) { * Logs diff of the given HTML docs to the console * @param {Object[]} diff * @param {Object} [options] - * @param {Number} [options.charsAroundDiff=20] + * @param {Number} [options.charsAroundDiff=40] */ function log(diff, options) { var diffText = getDiffText(diff, options); diff --git a/lib/index.js b/lib/index.js index afc87338..1e531558 100644 --- a/lib/index.js +++ b/lib/index.js @@ -183,7 +183,7 @@ function bemDiff(html1, html2) { compareHtmlAttrsAsJSON: ['data-bem', 'onclick', 'ondblclick'] }, loggerOptions = { - showCharacters: 20 + showCharacters: 40 }, htmlDiffer = new HtmlDiff(options); From d772a06f9a81402b2e46438ecd849cb8805666af Mon Sep 17 00:00:00 2001 From: Evgeniy Gavryushin Date: Tue, 22 Jul 2014 15:29:50 +0400 Subject: [PATCH 2/3] Update tests --- test/getDiffText.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/getDiffText.js b/test/getDiffText.js index fc44b6a4..5590a561 100644 --- a/test/getDiffText.js +++ b/test/getDiffText.js @@ -12,7 +12,7 @@ describe('\'diffHtml\'', function () { removed: undefined } ]; - diffLoger.getDiffText(inp).must.be.equal(''); + diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.equal(''); }); it('must return a diff string', function () { @@ -41,7 +41,7 @@ describe('\'diffHtml\'', function () { out = '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'Text'.grey + '!'.inverse.green + 'texttexttexttext'.grey; - diffLoger.getDiffText(inp).must.be.eql(out); + diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out); }); it('must consider negative value of \'charsAroundDiff\' option', function () { @@ -70,7 +70,7 @@ describe('\'diffHtml\'', function () { out = '\n' + 'texttexttexttexttexttexttexttexttexttexttext'.inverse.green + 'ololoololoololoololoololoololoololoololoolol'.inverse.red; - diffLoger.getDiffText(inp).must.be.eql(out); + diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out); }); it('must return a diff on the beginning of the input', function () { @@ -128,7 +128,7 @@ describe('\'diffHtml\'', function () { out = '\n...\n' + 'texttexttexttexttext'.grey + 'text'.inverse.red + 'texttexttexttexttext'.grey + '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'text'.grey + '!'.inverse.green + 'texttexttexttexttext'.grey; - diffLoger.getDiffText(inp).must.be.eql(out); + diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out); }); }); From 5b1b2f94cf224ef31747f552ea36d4b066e87af5 Mon Sep 17 00:00:00 2001 From: Evgeniy Gavryushin Date: Tue, 22 Jul 2014 15:30:05 +0400 Subject: [PATCH 3/3] Update README --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4f386d16..75966eaa 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ $ npm install html-differ -g **html-differ.diffHtml**
**@param** *String* - the 1-st ```html-code```
**@param** *String* - the 2-nd ```html-code```
-**@returns** *{Array of objects}* - see [here](https://github.com/kpdecker/jsdiff#examples) +**@returns** *{Array of objects}* - see [here](https://github.com/kpdecker/jsdiff#change-objects) **html-differ.isEqual**
This method has the same parameters as the previous one, but returns ```Boolean```. @@ -63,12 +63,12 @@ This method has the same parameters as the previous one, but returns ```Boolean` **@param** *{Object}* - the result of the work of the method ```html-differ.diffHtml```
**@param** *{Object}* - options:
* the number of characters before the diff and after it
-(for example, ```charsAroundDiff: 20```, default - ```20```, optional parameter)
+(for example, ```charsAroundDiff: 40```, default: ```40```)
**@returns** *{String}* - diffs **diff-logger.log**
-Pretty logging of diffs. Red text should be removed from the first html relative to the second one, green text should be added.
+Pretty logging of diffs.
This method has the same parameters as the previous one. ####Example#### @@ -95,9 +95,9 @@ var diff = htmlDiffer.diffHtml(html1, html2); var isEqual = htmlDiffer.isEqual(html1, html2); -var res = diffLogger.getDiffText(diff, { charsAroundDiff: 20 }); +var res = diffLogger.getDiffText(diff, { charsAroundDiff: 40 }); -diffLogger.log(diff, { charsAroundDiff: 20 }); +diffLogger.log(diff, { charsAroundDiff: 40 }); ``` where ```options``` is the ```Object```: @@ -123,7 +123,7 @@ Options for BEM are predefined: * ```ignoreWhitespace: true``` -* ```charsAroundDiff: 20``` +* ```charsAroundDiff: 40``` ###As a program### @@ -131,7 +131,6 @@ Options for BEM are predefined: ```bash $ html-differ --help Compares two html-files -Red text should be removed from the first html relative to the second one, green text should be added Usage: html-differ [OPTIONS] [ARGS] @@ -152,7 +151,7 @@ Arguments: ```bash $ bin/html-differ path/to/html1 path/to/html2 -$ bin/html-differ --config=path/to/config path/to/html1 path/to/html2 --chars-around-diff=20 +$ bin/html-differ --config=path/to/config path/to/html1 path/to/html2 --chars-around-diff=40 ``` ####Configuration file###