Skip to content

Commit 106f180

Browse files
committed
Merge pull request #62 from bem/issue61
Issue61
2 parents 1b79ef5 + 5b1b2f9 commit 106f180

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $ npm install html-differ -g
5252
**html-differ.diffHtml**<br>
5353
**@param** *String* - the 1-st ```html-code```<br>
5454
**@param** *String* - the 2-nd ```html-code```<br>
55-
**@returns** *{Array of objects}* - see [here](https://github.com/kpdecker/jsdiff#examples)
55+
**@returns** *{Array of objects}* - see [here](https://github.com/kpdecker/jsdiff#change-objects)
5656

5757
**html-differ.isEqual**<br>
5858
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`
6363
**@param** *{Object}* - the result of the work of the method ```html-differ.diffHtml```<br>
6464
**@param** *{Object}* - options:<br>
6565
* the number of characters before the diff and after it<br>
66-
(for example, ```charsAroundDiff: 20```, default - ```20```, optional parameter)<br>
66+
(for example, ```charsAroundDiff: 40```, default: ```40```)<br>
6767

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

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

7474
####Example####
@@ -95,9 +95,9 @@ var diff = htmlDiffer.diffHtml(html1, html2);
9595

9696
var isEqual = htmlDiffer.isEqual(html1, html2);
9797

98-
var res = diffLogger.getDiffText(diff, { charsAroundDiff: 20 });
98+
var res = diffLogger.getDiffText(diff, { charsAroundDiff: 40 });
9999

100-
diffLogger.log(diff, { charsAroundDiff: 20 });
100+
diffLogger.log(diff, { charsAroundDiff: 40 });
101101
```
102102

103103
where ```options``` is the ```Object```:
@@ -123,15 +123,14 @@ Options for BEM are predefined:
123123

124124
* ```ignoreWhitespace: true```
125125

126-
* ```charsAroundDiff: 20```
126+
* ```charsAroundDiff: 40```
127127

128128

129129
###As a program###
130130

131131
```bash
132132
$ html-differ --help
133133
Compares two html-files
134-
Red text should be removed from the first html relative to the second one, green text should be added
135134

136135
Usage:
137136
html-differ [OPTIONS] [ARGS]
@@ -152,7 +151,7 @@ Arguments:
152151
```bash
153152
$ bin/html-differ path/to/html1 path/to/html2
154153

155-
$ bin/html-differ --config=path/to/config path/to/html1 path/to/html2 --chars-around-diff=20
154+
$ bin/html-differ --config=path/to/config path/to/html1 path/to/html2 --chars-around-diff=40
156155
```
157156

158157
####Configuration file###

lib/cli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ module.exports = require('coa').Cmd()
2727
.end()
2828
.opt()
2929
.name('charsAroundDiff')
30-
.title('The number of characters around the diff')
30+
.title('The number of characters around the diff (default: 40)')
3131
.long('chars-around-diff')
32+
.def(40)
3233
.val(function(val) {
3334
return parseInt(val);
3435
})
@@ -53,7 +54,7 @@ module.exports = require('coa').Cmd()
5354

5455
var options = utils.defaults(config),
5556
loggerOptions = {
56-
charsAroundDiff: opts.charsAroundDiff || 20
57+
charsAroundDiff: opts.charsAroundDiff
5758
};
5859

5960
htmlDiffer = new HtmlDiffer(options),

lib/diff-logger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ require('colors');
44
* Returns readable diff text
55
* @param {Object[]} diff
66
* @param {Object} [options]
7-
* @param {Number} [options.charsAroundDiff=20]
7+
* @param {Number} [options.charsAroundDiff=40]
88
* @returns {String}
99
*/
1010
function getDiffText(diff, options) {
1111
options = options || {
12-
charsAroundDiff: 20
12+
charsAroundDiff: 40
1313
};
1414

1515
if (options.showCharacters) {
@@ -21,7 +21,7 @@ function getDiffText(diff, options) {
2121
output = '';
2222

2323
if (charsAroundDiff < 0) {
24-
charsAroundDiff = 20;
24+
charsAroundDiff = 40;
2525
}
2626

2727
if (diff.length === 1 && !diff[0].added && !diff[0].removed) return output;
@@ -58,7 +58,7 @@ function getDiffText(diff, options) {
5858
* Logs diff of the given HTML docs to the console
5959
* @param {Object[]} diff
6060
* @param {Object} [options]
61-
* @param {Number} [options.charsAroundDiff=20]
61+
* @param {Number} [options.charsAroundDiff=40]
6262
*/
6363
function log(diff, options) {
6464
var diffText = getDiffText(diff, options);

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function bemDiff(html1, html2) {
183183
compareHtmlAttrsAsJSON: ['data-bem', 'onclick', 'ondblclick']
184184
},
185185
loggerOptions = {
186-
showCharacters: 20
186+
showCharacters: 40
187187
},
188188

189189
htmlDiffer = new HtmlDiff(options);

test/getDiffText.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('\'diffHtml\'', function () {
1212
removed: undefined
1313
} ];
1414

15-
diffLoger.getDiffText(inp).must.be.equal('');
15+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.equal('');
1616
});
1717

1818
it('must return a diff string', function () {
@@ -41,7 +41,7 @@ describe('\'diffHtml\'', function () {
4141

4242
out = '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'Text'.grey + '!'.inverse.green + 'texttexttexttext'.grey;
4343

44-
diffLoger.getDiffText(inp).must.be.eql(out);
44+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
4545
});
4646

4747
it('must consider negative value of \'charsAroundDiff\' option', function () {
@@ -70,7 +70,7 @@ describe('\'diffHtml\'', function () {
7070

7171
out = '\n' + 'texttexttexttexttexttexttexttexttexttexttext'.inverse.green + 'ololoololoololoololoololoololoololoololoolol'.inverse.red;
7272

73-
diffLoger.getDiffText(inp).must.be.eql(out);
73+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
7474
});
7575

7676
it('must return a diff on the beginning of the input', function () {
@@ -128,7 +128,7 @@ describe('\'diffHtml\'', function () {
128128

129129
out = '\n...\n' + 'texttexttexttexttext'.grey + 'text'.inverse.red + 'texttexttexttexttext'.grey + '\n...\n' + 'texttexttexttexttext'.grey + '!'.inverse.green + 'text'.grey + '!'.inverse.green + 'texttexttexttexttext'.grey;
130130

131-
diffLoger.getDiffText(inp).must.be.eql(out);
131+
diffLoger.getDiffText(inp, { charsAroundDiff: 20 } ).must.be.eql(out);
132132
});
133133

134134
});

0 commit comments

Comments
 (0)