Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $ npm install html-differ -g
**html-differ.diffHtml**<br>
**@param** *String* - the 1-st ```html-code```<br>
**@param** *String* - the 2-nd ```html-code```<br>
**@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**<br>
This method has the same parameters as the previous one, but returns ```Boolean```.
Expand All @@ -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```<br>
**@param** *{Object}* - options:<br>
* the number of characters before the diff and after it<br>
(for example, ```charsAroundDiff: 20```, default - ```20```, optional parameter)<br>
(for example, ```charsAroundDiff: 40```, default: ```40```)<br>

**@returns** *{String}* - diffs

**diff-logger.log**<br>
Pretty logging of diffs. Red text should be removed from the first html relative to the second one, green text should be added.<br>
Pretty logging of diffs.<br>
This method has the same parameters as the previous one.

####Example####
Expand All @@ -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```:
Expand All @@ -123,15 +123,14 @@ Options for BEM are predefined:

* ```ignoreWhitespace: true```

* ```charsAroundDiff: 20```
* ```charsAroundDiff: 40```


###As a program###

```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]
Expand All @@ -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###
Expand Down
5 changes: 3 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand All @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions lib/diff-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function bemDiff(html1, html2) {
compareHtmlAttrsAsJSON: ['data-bem', 'onclick', 'ondblclick']
},
loggerOptions = {
showCharacters: 20
showCharacters: 40
},

htmlDiffer = new HtmlDiff(options);
Expand Down
8 changes: 4 additions & 4 deletions test/getDiffText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
});

});