smart_diff 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cf02a3500e0380989296dfce081facae794b7b1
4
+ data.tar.gz: 40db6403781250648e874d07766a77fd7c84d53d
5
+ SHA512:
6
+ metadata.gz: 5c3a76c3c50d0cfd447e208d3f0b74b73cdc9a9943ac3ad7d06075c1cee97f5181859a5c3a4610d952bdb3349a6622724c4943e9fe04259dc440b7c70e36acf0
7
+ data.tar.gz: 0d2613f418b7896dd7180d02c694387b42de4af1f934412fabfba9b38a30744d078366cc9ce7089fd1f0aeef0972f9675a76d36406f13430f3d62bce68523722
data/Example.html ADDED
@@ -0,0 +1,506 @@
1
+
2
+ <html>
3
+
4
+ <head>
5
+
6
+ <META http-equiv="Content-Type" content="text/html; charset=utf-8">
7
+
8
+ <style>
9
+
10
+ .d { /* deleted */
11
+ border: solid 1px #CC929A;
12
+ border-radius: 3px;
13
+ background-color: #FCBFBA;
14
+ }
15
+
16
+ .i { /* inserted */
17
+ border: solid 1px #73BE73;
18
+ border-radius: 3px;
19
+ background-color: #98FB98;
20
+ }
21
+
22
+ .c { /* changed */
23
+ border: solid 1px #8AADB8;
24
+ background-color: LightBlue;
25
+ border-radius: 3px;
26
+ cursor: pointer;
27
+ }
28
+
29
+ .m { /* moved */
30
+ border: solid 1px #A9A9A9;
31
+ border-radius: 3px;
32
+ cursor: crosshair;
33
+ }
34
+
35
+ .mc {
36
+ border: solid 1px LightPink;
37
+ background-color: LightBlue;
38
+ cursor: pointer;
39
+ }
40
+
41
+ .u { /* unchanged */
42
+ border: solid 1px #A9A9A9;
43
+ border-radius: 4px;
44
+ cursor: crosshair;
45
+ }
46
+
47
+ span.lineno {
48
+ color: lightgrey;
49
+ -webkit-user-select: none;
50
+ -moz-user-select: none;
51
+ }
52
+
53
+ span.keyword {
54
+ /* color: #007070; */
55
+ font-weight: 700;
56
+ }
57
+
58
+ div.line {
59
+ }
60
+
61
+ div.src {
62
+ width:48%;
63
+ height:98%;
64
+ overflow:scroll;
65
+ float:left;
66
+ padding:0.5%;
67
+ border: solid 2px LightGrey;
68
+ border-radius: 5px;
69
+ }
70
+
71
+
72
+ div.stats {
73
+ border: solid 1px grey;
74
+ z-index: 1000;
75
+ width: 80%;
76
+ padding-left: 5%;
77
+ }
78
+
79
+ pre.stats {
80
+ color: grey;
81
+ -webkit-user-select: none;
82
+ -moz-user-select: none;
83
+ }
84
+
85
+ pre {
86
+ line-height: 200%;
87
+ }
88
+
89
+ p {
90
+ line-height: 200%;
91
+ }
92
+
93
+ ::-webkit-scrollbar {
94
+ width: 10px;
95
+ }
96
+
97
+ ::-webkit-scrollbar-track {
98
+ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
99
+ border-radius: 10px;
100
+ }
101
+
102
+ ::-webkit-scrollbar-thumb {
103
+ border-radius: 10px;
104
+ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
105
+ }
106
+
107
+
108
+ </style>
109
+
110
+
111
+ <script type="text/javascript">
112
+
113
+ // convenience function for document.getElementById().
114
+ window['$']=function(a){return document.getElementById(a)};
115
+
116
+
117
+ /////////////////////// debug flag ////////////////////////
118
+ var debug = false;
119
+
120
+
121
+ /////////////////////// adjustable parameters //////////////////
122
+ var minStep = 10;
123
+ var nSteps = 30;
124
+ var stepInterval = 10;
125
+ var blockRange = 5; // how far consider one page blocked
126
+ var nodeHLColor = '#C9B0A9';
127
+ var lineHLColor = '#FFFF66';
128
+ var lineBlockedColor = '#E9AB17';
129
+ var bgColor = '';
130
+ var bodyBlockedColor = '#FAF0E6';
131
+
132
+
133
+ ///////////////////////// globals ////////////////////////
134
+ var eventCount = { 'left' : 0, 'right' : 0};
135
+ var moving = false;
136
+ var matchId1 = 'leftstart';
137
+ var matchId2 = 'rightstart';
138
+ var matchLineId1 = -1;
139
+ var matchLineId2 = -1;
140
+ var cTimeout;
141
+
142
+
143
+ ///////////////////////// utilities ///////////////////////
144
+
145
+ // No Math.sign() in JS?
146
+ function sign(x) {
147
+ if (x > 0) {
148
+ return 1;
149
+ } else if (x < 0) {
150
+ return -1;
151
+ } else {
152
+ return 0;
153
+ }
154
+ }
155
+
156
+
157
+ function log(msg) {
158
+ if (debug) {
159
+ console.log(msg);
160
+ }
161
+ }
162
+
163
+
164
+
165
+ function elementPosition(id) {
166
+ obj = $(id);
167
+ var curleft = 0, curtop = 0;
168
+
169
+ if (obj && obj.offsetParent) {
170
+ curleft = obj.offsetLeft;
171
+ curtop = obj.offsetTop;
172
+
173
+ while (obj = obj.offsetParent) {
174
+ curleft += obj.offsetLeft;
175
+ curtop += obj.offsetTop;
176
+ }
177
+ }
178
+
179
+ return { x: curleft, y: curtop };
180
+ }
181
+
182
+
183
+ /*
184
+ * Scroll the window to relative position, detecting blocking positions.
185
+ */
186
+ function scrollWithBlockCheck(container, distX, distY) {
187
+ var oldTop = container.scrollTop;
188
+ var oldLeft = container.scrollLeft;
189
+
190
+ container.scrollTop += distY; // the ONLY place for actual scrolling
191
+ container.scrollLeft += distX;
192
+
193
+ var actualX = container.scrollLeft - oldLeft;
194
+ var actualY = container.scrollTop - oldTop;
195
+ log("distY=" + distY + ", actualY=" + actualY);
196
+ log("distX=" + distX + ", actualX=" + actualX);
197
+
198
+ // extra leewaw here because Chrome scrolling is horribly inacurate
199
+ if ((Math.abs(distX) > blockRange && actualX === 0)
200
+ || Math.abs(distY) > blockRange && actualY === 0) {
201
+ log("blocked");
202
+ container.style.backgroundColor = bodyBlockedColor;
203
+ return true;
204
+ } else {
205
+ eventCount[container.id] += 1;
206
+ container.style.backgroundColor = bgColor;
207
+ return false;
208
+ }
209
+ }
210
+
211
+
212
+ function getContainer(elm) {
213
+ while (elm && elm.tagName !== 'DIV') {
214
+ elm = elm.parentElement || elm.parentNode;
215
+ }
216
+ return elm;
217
+ }
218
+
219
+
220
+ /*
221
+ * timed animation function for scrolling the current window
222
+ */
223
+ function matchWindow(linkId, targetId, n)
224
+ {
225
+ moving = true;
226
+
227
+ var link = $(linkId);
228
+ var target = $(targetId);
229
+ var linkContainer = getContainer(link);
230
+ var targetContainer = getContainer(target);
231
+
232
+ var linkPos = elementPosition(linkId).y - linkContainer.scrollTop;
233
+ var targetPos = elementPosition(targetId).y - targetContainer.scrollTop;
234
+ var distY = targetPos - linkPos;
235
+ var distX = linkContainer.scrollLeft - targetContainer.scrollLeft;
236
+
237
+
238
+ log("matching window... " + n + " distY=" + distY + " distX=" + distX);
239
+
240
+ if (distY === 0 && distX === 0) {
241
+ clearTimeout(cTimeout);
242
+ moving = false;
243
+ } else if (n <= 1) {
244
+ scrollWithBlockCheck(targetContainer, distX, distY);
245
+ moving = false;
246
+ } else {
247
+ var stepSize = Math.floor(Math.abs(distY) / n);
248
+ actualMinStep = Math.min(minStep, Math.abs(distY));
249
+ if (Math.abs(stepSize) < minStep) {
250
+ var step = actualMinStep * sign(distY);
251
+ } else {
252
+ var step = stepSize * sign(distY);
253
+ }
254
+ var blocked = scrollWithBlockCheck(targetContainer, distX, step);
255
+ var rest = Math.floor(distY / step) - 1;
256
+ log("blocked?" + blocked + ", rest steps=" + rest);
257
+ if (!blocked) {
258
+ cTimeout = setTimeout(function () {
259
+ return matchWindow(linkId, targetId, rest);
260
+ }, stepInterval);
261
+ } else {
262
+ clearTimeout(cTimeout);
263
+ moving = false;
264
+ }
265
+ }
266
+ }
267
+
268
+
269
+ function showArrow(linkId, targetId)
270
+ {
271
+ var link = $(linkId);
272
+ var target = $(targetId);
273
+ var linkContainer = getContainer(link);
274
+ var targetContainer = getContainer(target);
275
+
276
+ var linkPos = elementPosition(linkId).y - linkContainer.scrollTop;
277
+ var targetPos = elementPosition(targetId).y - targetContainer.scrollTop;
278
+ var distY = targetPos - linkPos;
279
+ var distX = linkContainer.scrollLeft - targetContainer.scrollLeft;
280
+
281
+
282
+ log("targetPos = " + targetPos);
283
+ }
284
+
285
+
286
+ ////////////////////////// highlighting /////////////////////////////
287
+
288
+ var highlighted = []
289
+ function putHighlight(id, color) {
290
+ var elm = $(id);
291
+ if (elm !== null) {
292
+ elm.style.backgroundColor = color;
293
+ if (color !== bgColor) {
294
+ highlighted.push(id);
295
+ }
296
+ }
297
+ }
298
+
299
+
300
+ function clearHighlight() {
301
+ for (i = 0; i < highlighted.length; i += 1) {
302
+ putHighlight(highlighted[i], bgColor);
303
+ }
304
+ highlighted = [];
305
+ }
306
+
307
+
308
+
309
+ /*
310
+ * Highlight the link, target nodes and their lines,
311
+ * then start animation to move the other window to match.
312
+ */
313
+ function highlight(me, linkId, targetId)
314
+ {
315
+ if (me.id === 'left') {
316
+ matchId1 = linkId;
317
+ matchId2 = targetId;
318
+ } else {
319
+ matchId1 = targetId;
320
+ matchId2 = linkId;
321
+ }
322
+
323
+ clearHighlight();
324
+
325
+ putHighlight(linkId, nodeHLColor);
326
+ putHighlight(targetId, nodeHLColor);
327
+ }
328
+
329
+
330
+ function instantMoveOtherWindow (me) {
331
+ log("me=" + me.id + ", eventcount=" + eventCount[me.id]);
332
+ log("matchId1=" + matchId1 + ", matchId2=" + matchId2);
333
+
334
+ me.style.backgroundColor = bgColor;
335
+
336
+ if (!moving && eventCount[me.id] === 0) {
337
+ if (me.id === 'left') {
338
+ matchWindow(matchId1, matchId2, 1);
339
+ } else {
340
+ matchWindow(matchId2, matchId1, 1);
341
+ }
342
+ }
343
+ if (eventCount[me.id] > 0) {
344
+ eventCount[me.id] -= 1;
345
+ }
346
+ }
347
+
348
+
349
+ function getTarget(x){
350
+ x = x || window.event;
351
+ return x.target || x.srcElement;
352
+ }
353
+
354
+
355
+ window.onload =
356
+ function (e) {
357
+ var tags = document.getElementsByTagName("A")
358
+ for (var i = 0; i < tags.length; i++) {
359
+ tags[i].onmouseover =
360
+ function (e) {
361
+ var t = getTarget(e)
362
+ var lid = t.id
363
+ var tid = t.getAttribute('tid')
364
+ var container = getContainer(t)
365
+ highlight(container, lid, tid)
366
+ showArrow(lid, tid)
367
+ }
368
+ tags[i].onclick =
369
+ function (e) {
370
+ var t = getTarget(e)
371
+ var lid = t.id
372
+ var tid = t.getAttribute('tid')
373
+ var container = getContainer(t)
374
+ highlight(container, lid, tid)
375
+ matchWindow(lid, tid, nSteps)
376
+ }
377
+ }
378
+
379
+ tags = document.getElementsByTagName("DIV")
380
+ for (var i = 0; i < tags.length; i++) {
381
+ tags[i].onscroll =
382
+ function (e) {
383
+ instantMoveOtherWindow(getTarget(e))
384
+ }
385
+ }
386
+
387
+ }
388
+
389
+
390
+ </script>
391
+
392
+ </head>
393
+
394
+ <body>
395
+
396
+ <div>
397
+ <div id="left" class="src"><pre><a id="leftstart" tid="rightstart"></a>require &quot;pathname&quot;
398
+ require &quot;filetree/simple_tree&quot;
399
+
400
+ class Pathname
401
+ alias :_parent :parent
402
+ alias :_children :children
403
+ end
404
+
405
+ class FileTree &lt; Pathname
406
+ include SimpleTree
407
+
408
+ attr_accessor :name, :id, :identifier
409
+
410
+ <a id='0' tid='1' class='c'>def name
411
+ @name ||= self.inspect
412
+ end</a>
413
+
414
+ <a id='2' tid='3' class='c'>def id
415
+ @id ||= self.inspect
416
+ end</a>
417
+
418
+ <a id='4' tid='5' class='c'>def identifier
419
+ @identifier ||= self.inspect
420
+ end</a>
421
+
422
+ #
423
+ # See {http://rubydoc.info/stdlib/pathname/Pathname:parent Pathname.parent}
424
+ #
425
+ # @return [FileTree] The directory immediately above self.
426
+ #
427
+ <a id='6' tid='7' class='c'>def parent
428
+ <span class='i'>puts <span class='i'>&quot;Here's Johnny!&quot;</span></span>
429
+ FileTree.new(_parent)
430
+ end</a>
431
+
432
+ #
433
+ # See {http://rubydoc.info/stdlib/pathname/Pathname:children Pathname.children}
434
+ #
435
+ # @return [Array] an Array of all entries contained in self.
436
+ #
437
+ <a id='8' tid='9' class='c'>def children(*args)
438
+ if self.directory?
439
+ _children(*args)
440
+ else
441
+ []
442
+ end
443
+ end</a>
444
+
445
+ end
446
+
447
+ puts <span class='i'>&quot;And now for something completely different&quot;</span>
448
+ </pre></div><div id="right" class="src"><pre><a id="rightstart" tid="leftstart"></a>require &quot;pathname&quot;
449
+ require &quot;filetree/simple_tree&quot;
450
+
451
+ class Pathname
452
+ alias :_parent :parent
453
+ alias :_children :children
454
+ end
455
+
456
+ class FileTree &lt; Pathname
457
+ include SimpleTree
458
+
459
+ attr_accessor :name, :id, :identifier
460
+
461
+ #
462
+ # See {http://rubydoc.info/stdlib/pathname/Pathname:parent Pathname.parent}
463
+ #
464
+ # @return [FileTree] The directory immediately above self.
465
+ #
466
+ <a id='7' tid='6' class='c'>def parent
467
+ ft = FileTree.new(_parent)
468
+ <span class='d'><span class='d'>return ft</span></span>
469
+ end</a>
470
+
471
+ <a id='3' tid='2' class='c'>def id
472
+ @id ||= self.inspect
473
+ <span class='d'>puts <span class='d'>@id</span></span>
474
+ end</a>
475
+
476
+ <a id='1' tid='0' class='c'>def name
477
+ @name ||= self.inspect
478
+ end</a>
479
+
480
+ #
481
+ # See {http://rubydoc.info/stdlib/pathname/Pathname:children Pathname.children}
482
+ #
483
+ # @return [Array] an Array of all entries contained in self.
484
+ #
485
+ <a id='9' tid='8' class='c'>def children(*args)
486
+ if self.directory?
487
+ _children(*args)
488
+ else
489
+ []
490
+ end
491
+ end</a>
492
+
493
+ <a id='5' tid='4' class='c'>def identifier
494
+ @identifier ||= self.inspect
495
+ end</a>
496
+
497
+ end
498
+
499
+ puts <span class='d'>&quot;Some stuff&quot;</span>
500
+ </pre>
501
+ </div>
502
+ </div>
503
+
504
+ </body>
505
+
506
+ </html>
data/README.md CHANGED
@@ -11,13 +11,13 @@ something quite similar (create a diff of source code based on the AST rather th
11
11
 
12
12
  This application should especially serve as an example of using the subdiff's
13
13
  produced by NodeDiff to improve the quality of the output. See `bin/smart_diff`
14
- .
14
+ or [check out the docs](http://rubydoc.info/gems/smart_diff/0.0.1/frames).
15
15
 
16
16
  ## Install
17
17
 
18
- ```
19
- $ jruby -S gem install smart_diff
20
- ```
18
+
19
+ $ jruby -S gem install smart_diff
20
+
21
21
 
22
22
  ## Usage
23
23
 
@@ -25,7 +25,7 @@ Run `smart_diff` along with the paths to two versions of a ruby source file.
25
25
 
26
26
  smart_diff example/bar.rb example/foo.rb
27
27
 
28
- This will output an html file you can open in your browser. Check out `foo.rb-bar.rb.html` for a sample of the output.
28
+ This will output an html file you can open in your browser. Check out [Example.html](http://edubkendo.github.io/smart_diff/file.Example.html) for a sample of the output.
29
29
 
30
30
  LICENSE
31
31