-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.coffee
41 lines (37 loc) · 1.21 KB
/
main.coffee
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
Email = require('email').Email
class Mailer
constructor : (params) ->
@file = params.path
@from = params.from
@to = params.to
console.log "Ready!"
receiver : ({diff}) =>
msg = new Email
from: @from
to: @to
subject: "File #{@file} has been modified"
body: "File #{@file} has been modified.\nThe changes are:\n\n" + @format diff
msg.send (err) ->
console.log 'ERROR:', err if err
format : (diff) ->
string = ""
aOffset = 0
rOffset = 0
for change in diff
line = ""
if change.type is 'ellipsis'
line += "[#{change.size} omitted lines]\n"
else if change.type is 'fill'
for subLine, i in change.lines
line += "#{change.start + i - rOffset}\t#{change.start + i - rOffset}\t= #{subLine}\n"
else if change.type is 'add'
for subLine, i in change.lines
line += "\t#{change.start + i - rOffset}\t> #{subLine}\n"
aOffset += change.lines.length
else if change.type is 'rem'
for subLine, i in change.lines
line += "#{change.start + i - aOffset}\t\t< #{subLine}\n"
rOffset += change.lines.length
string += line
string + "[EOF]\n"
module.exports = Mailer