File: diffmail.rb

package info (click to toggle)
hiki 0.8.7-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,796 kB
  • ctags: 1,736
  • sloc: ruby: 20,269; lisp: 926; sh: 269; makefile: 12
file content (50 lines) | stat: -rw-r--r-- 1,617 bytes parent folder | download | duplicates (3)
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
# $Id: diffmail.rb,v 1.11 2005/07/17 14:29:06 fdiary Exp $
# Copyright (C) 2004-2005 Kazuhiko <kazuhiko@fdiary.net>

#----- send a mail on updating
def updating_mail
  begin
    latest_text = @db.load(@page) || ''
    if @params['page_title'][0]
      title = @params['page_title'][0].empty? ? @page : @params['page_title'][0].strip
    else
      title = nil
    end
    if @params['keyword'][0]
      keyword = (@params['keyword'][0]||'').split("\n").collect {|k|
        k.chomp.strip}.delete_if{|k| k.empty?}.join(' / ')
    else
      keyword = nil
    end
    head = ''
    type = (!@db.text or @db.text.empty?) ? 'create' : 'update'
    if type == 'create' then
      head << "TITLE       = #{title}\n" if title
      head << "KEYWORD     = #{keyword}\n" if keyword
      r = "#{latest_text}\n"
    elsif type == 'update'
      title_old = CGI::unescapeHTML( page_name( @page ) )
      keyword_old = @db.get_attribute(@page, :keyword).join(' / ')
      if title && title != title_old
        head << "TITLE       = #{title_old} -> #{title}\n"
      end
      if keyword && keyword != keyword_old
        head << "KEYWORD     = #{keyword_old} -> #{keyword}\n"
      end
      head << "-------------------------\n" unless head.empty?

      src = @db.text
      dst = latest_text
      diff_style = @options['diffmail.style'] || 0
      case diff_style.to_i
      when 0
	unified = @options['diffmail.lines'] || 3
	r = unified_diff( src, dst, unified )
      when 1
	r = word_diff_text( src, dst, true )
      end
    end
    send_updating_mail(@page, type, head + r) unless (head + r).empty?
  rescue
  end
end