Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
* master:
  Refactor for issue #31
  Update README.md
  • Loading branch information
amweiss committed Aug 17, 2016
2 parents 7a03cda + 37c2ce5 commit 8b78d2b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular-diff-match-patch

This library is simply a wrapper around [google-diff-match-patch](https://code.google.com/p/google-diff-match-patch/).

![Simple](http://i.imgur.com/BFHwYtq.png)
![Simple](http://amweiss.github.io/angular-diff-match-patch/simple.png)

(Shown here with some custom styles)

Expand Down
21 changes: 10 additions & 11 deletions angular-diff-match-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,26 @@ angular.module('diff-match-patch', [])
}

function getTagAttrs(options, op, attrs) {
var tagOptions = new Map();
var tagOptions = {};
var retVal = [];
var opName = diffAttrName(op);

if (angular.isDefined(options) && angular.isDefined(options.attrs) && options.attrs instanceof Map && options.attrs.has(opName)) {
options.attrs.get(opName).forEach(function (value, key) {
tagOptions.set(key, value);
});
if (angular.isDefined(options) && angular.isDefined(options.attrs)) {
var attributesFromOptions = options.attrs[opName];
if (angular.isDefined(attributesFromOptions)) {
angular.merge(tagOptions, attributesFromOptions);
}
}

if (angular.isDefined(attrs)) {
attrs.forEach(function (value, key) {
tagOptions.set(key, value);
});
angular.merge(tagOptions, attrs);
}

if (tagOptions.size === 0) {
if (Object.keys(tagOptions).length === 0) {
return '';
}

tagOptions.forEach(function (value, key) {
angular.forEach(tagOptions, function (value, key) {
retVal.push(key + '="' + value + '"');
});

Expand All @@ -86,7 +85,7 @@ angular.module('diff-match-patch', [])
function getHtmlPrefix(op, display, options) {
switch (display) {
case displayType.LINEDIFF:
return '<div class="' + diffClass(op) + '"><span' + getTagAttrs(options, op, new Map().set('class', 'noselect')) + '>' + diffSymbol(op) + '</span>';
return '<div class="' + diffClass(op) + '"><span' + getTagAttrs(options, op, {class: 'noselect'}) + '>' + diffSymbol(op) + '</span>';
default: // case displayType.INSDEL:
return '<' + diffTag(op) + getTagAttrs(options, op) + '>';
}
Expand Down
18 changes: 14 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@
$scope.options = {
editCost: 4,
interLineDiff: true,
attrs: new Map().set('insert', new Map().set('data-attr','insert').set('class','insertion'))
.set('delete', new Map().set('data-attr', 'delete'))
.set('equal', new Map().set('data-attr', 'equal'))
attrs: {
insert: {
'data-attr': 'insert',
'class': 'insertion'
},
delete: {
'data-attr': 'delete'
},
equal: {
'data-attr': 'equal'
}
}
};
}]);
</script>
Expand Down Expand Up @@ -127,7 +136,8 @@ <h2>diff</h2>
<h2>processingDiff</h2>
<span flex></span>
<md-input-container>
<label>editCost</label><input type="number" step="1" name="editCost" ng-model="options.editCost" min="1" max="99999">
<label>editCost</label><input type="number" step="1" name="editCost" ng-model="options.editCost" min="1"
max="99999">
</md-input-container>
</div>
<pre class="textdiff" processing-diff left-obj="left" right-obj="right" options="options"></pre>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"devDependencies": {
"angular-mocks": "^1.*",
"es6-shim": "^0.35.1",
"http-server": "^0.9",
"jasmine-core": "^2.*",
"karma": "^1.*",
Expand Down
33 changes: 25 additions & 8 deletions test/diffmatchpatch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ describe('diff-match-patch', function diffMatchPatchDescription() {
var oneLineBasicLeft = 'hello world';
var oneLineBasicRight = 'hello';
var multiLineLeft = ['I know the kings of England, and I quote the fights historical,',
'From Marathon to Waterloo, in order categorical.'].join('\n');
'From Marathon to Waterloo, in order categorical.'].join('\n');
var multiLineRight = ['I\'m quite adept at funny gags, comedic theory I have read',
'From wicked puns and stupid jokes to anvils that drop on your head.'].join('\n');
'From wicked puns and stupid jokes to anvils that drop on your head.'].join('\n');
var diffRegex = '<span.*?>hello</span><del.*?> world</del>';

beforeEach(module('diff-match-patch'));
Expand Down Expand Up @@ -66,9 +66,17 @@ describe('diff-match-patch', function diffMatchPatchDescription() {
$scope.left = ['hello', 'world'].join('\n');
$scope.right = ['hello', 'friends!'].join('\n');
$scope.options = {
attrs: new Map().set('insert', new Map().set('data-attr', 'insert'))
.set('delete', new Map().set('data-attr', 'delete'))
.set('equal', new Map().set('data-attr', 'equal'))
attrs: {
insert: {
'data-attr': 'insert'
},
delete: {
'data-attr': 'delete'
},
equal: {
'data-attr': 'equal'
}
}
};

$scope.$digest();
Expand Down Expand Up @@ -217,9 +225,18 @@ describe('diff-match-patch', function diffMatchPatchDescription() {
$scope.left = ['hello', 'world'].join('\n');
$scope.right = ['hello', 'friends!'].join('\n');
$scope.options = {
attrs: new Map().set('insert', new Map().set('data-attr', 'insert').set('class', 'insertion'))
.set('delete', new Map().set('data-attr', 'delete'))
.set('equal', new Map().set('data-attr', 'equal'))
attrs: {
insert: {
'data-attr': 'insert',
'class': 'insertion'
},
delete: {
'data-attr': 'delete'
},
equal: {
'data-attr': 'equal'
}
}
};

$scope.$digest();
Expand Down
1 change: 0 additions & 1 deletion test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module.exports = function (config) {

// list of files / patterns to load in the browser
files: [
'node_modules/es6-shim/es6-shim.min.js',
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/diff-match-patch/index.js',
Expand Down

0 comments on commit 8b78d2b

Please sign in to comment.