HTMLDiff (Module)

In: libraries/diff/diff.rb

Methods

Classes and Modules

Class HTMLDiff::Builder

Included Modules

Public Class methods

[Source]

     # File libraries/diff/diff.rb, line 399
399:   def self.diff(a, b)
400:     a, b = a.split(//), b.split(//) if a.kind_of? String and b.kind_of? String
401:     a, b = html2list(a), html2list(b)
402: 
403:     out = Builder.new(a, b)
404:     s = SequenceMatcher.new(a, b)
405: 
406:     s.get_opcodes.each do |opcode|
407:       out.do_op(opcode)
408:     end
409: 
410:     out.result 
411:   end

[Source]

     # File libraries/diff/diff.rb, line 413
413:   def self.html2list(x, b=false)
414:     mode = 'char'
415:     cur = ''
416:     out = []
417:     
418:     x = x.split(//) if x.kind_of? String
419:     
420:     x.each do |c|
421:       if mode == 'tag'
422:         if c == '>'
423:           if b
424:             cur += ']'
425:           else
426:             cur += c
427:           end
428:           out.push(cur)
429:           cur = ''
430:           mode = 'char'
431:         else
432:           cur += c
433:         end
434:       elsif mode == 'char'
435:         if c == '<'
436:           out.push cur
437:           if b
438:             cur = '['
439:           else
440:             cur = c
441:           end
442:           mode = 'tag'
443:         elsif /\s/.match c
444:           out.push cur + c
445:           cur = ''
446:         else
447:           cur += c
448:         end
449:       end
450:     end
451:     
452:     out.push cur
453:     # TODO: make something better here

454:     out.each{|x| x.chomp! unless is_newline(x)}
455:     out.find_all { |x| x != '' }
456:   end

[Source]

     # File libraries/diff/diff.rb, line 387
387:   def self.is_newline(x)
388:     (x == "\n") or (x == "\r") or (x == "\t")
389:   end

[Source]

     # File libraries/diff/diff.rb, line 395
395:   def self.is_p_close_tag(x)
396:     x =~ %!\A</(p|li|ul|ol|dir|dt|dl)!
397:   end

[Source]

     # File libraries/diff/diff.rb, line 391
391:   def self.is_p_open_tag(x)
392:     x =~ /\A<(p|li|ul|ol|dir|dt|dl)/
393:   end

[Validate]