Module: HTMLDiff
- Includes:
- Diff
- Defined in:
- lib/diff.rb
Defined Under Namespace
Classes: Builder
Class Method Summary
collapse
Methods included from Diff
calculate_ratio, count_leading, get_close_matches
Class Method Details
.diff(a, b) ⇒ Object
399
400
401
402
403
404
405
406
407
408
409
410
411
|
# File 'lib/diff.rb', line 399
def self.diff(a, b)
a = html2list(a)
b = html2list(b)
out = Builder.new(a, b)
s = SequenceMatcher.new(a, b)
s.get_opcodes.each do |opcode|
out.do_op(opcode)
end
out.result
end
|
.html2list(x) ⇒ Object
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
# File 'lib/diff.rb', line 413
def self.html2list(x)
mode = :char
cur = ''
out = []
x.split('').each do |c|
if mode == :tag
cur += c
if c == '>'
out.push(cur)
cur = ''
mode = :char
end
elsif mode == :char
if c == '<'
out.push cur
cur = c
mode = :tag
elsif c =~ /\s/
out.push cur + c
cur = ''
else
cur += c
end
end
end
out.push cur
out.find_all { |x| x != '' }
end
|
.is_newline(x) ⇒ Object
387
388
389
|
# File 'lib/diff.rb', line 387
def self.is_newline(x)
(x == "\n") or (x == "\r") or (x == "\t")
end
|
.is_p_close_tag(x) ⇒ Object
395
396
397
|
# File 'lib/diff.rb', line 395
def self.is_p_close_tag(x)
x =~ %r!\A</(p|li|ul|ol|dir|dt|dl)!
end
|
.is_p_open_tag(x) ⇒ Object
391
392
393
|
# File 'lib/diff.rb', line 391
def self.is_p_open_tag(x)
x =~ /\A<(p|li|ul|ol|dir|dt|dl)/
end
|