-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.app
70 lines (59 loc) · 2.49 KB
/
lib.app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module elib/elib-clientsidediff/lib
//Mark new or deleted files by setting name to /dev/null for the missing file
template showDiff( leftName : String, leftVersion : String, rightName : String, rightVersion : String){
var leftElemId := id+"_left"
var rightElemId := id+"_right"
var diffContainerId := id+"_diff"
diffIncludes
<input id=leftElemId type="hidden" value=leftVersion/>
<input id=rightElemId type="hidden" value=rightVersion />
div[id=diffContainerId]{}
<script>
$( function(){
let leftVal = $('#~leftElemId').val();
let leftSplit = leftVal !== '' ? leftVal.split('\n') : undefined;
let rightVal = $('#~rightElemId').val();
let rightSplit = rightVal !== '' ? rightVal.split('\n') : undefined;
let diff = difflib.unifiedDiff(
leftSplit,
rightSplit,
{
fromfile: '~leftName',
tofile: '~rightName',
lineterm: ''
}
);
//inject deleted/new file instructions when applicable, to display correct mode with Diff2HtmlUI
if(diff.length >= 2){
if( diff[1].endsWith("/dev/null") && !diff[2].includes('deleted file') ){
diff.splice(2, 0, "deleted file mode 000000");
} else if( diff[0].endsWith("/dev/null") && !diff[2].includes('new file') ){
diff.splice(2, 0, "new file mode 000000");
}
};
let diffStr = diff.join('\n');
let diffContainer = document.getElementById("~diffContainerId");
const diffDisplayConfig = {
drawFileList: false,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'lines',
outputFormat: 'line-by-line',
synchronisedScroll: true,
highlight: true,
renderNothingWhenEmpty: false
};
let diff2htmlUi = new Diff2HtmlUI(diffContainer, diffStr, diffDisplayConfig);
diff2htmlUi.draw();
} );
</script>
}
template diffIncludes(){
includeJS("difflib-browser.js")
// includeJS("diff2html-ui.min.js") //includes the wrapper of diff2html with highlight for all highlight.js supported languages
includeJS("diff2html-ui-slim.min.js") //includes the wrapper of diff2html with "the most common" highlight.js supported languages
// includeJS("diff2html-ui-base.min.js") //includes the wrapper of diff2html without including a highlight.js implementation. You can use it without syntax highlight or by passing your own implementation with the languages you prefer
includeCSS("highlight-js-github.css")
includeCSS("diff2html.min.css")
}