-
Notifications
You must be signed in to change notification settings - Fork 3
/
change.dylan
70 lines (64 loc) · 2.15 KB
/
change.dylan
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module: change
author: Hannes Mehnert <hannes@mehnert.org>
define web-class <change> (<object>)
data author :: <string>;
data date :: <date>;
data command :: <command>;
end;
define method initialize (change :: <change>, #rest rest, #key, #all-keys)
next-method();
change.date := current-date();
change.author := if (authenticated-user())
authenticated-user().user-name;
else
"foo"
end;
end;
define method setup (change :: <change>) => ()
redo(change.command);
end;
define method undo (change :: <change>)
//undo the change
undo(change.command);
//on success, make a new <change> object, add it to *changes*
let change = make(<change>,
command: reverse-command(change.command));
save(change);
end;
define method print-xml (date :: <date>, #key base-url)
list(with-xml()
text(print-change(date))
end);
end;
define method print-change (date :: <date>, #key base-url)
let $month-names
= #["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
let (iyear, imonth, iday, ihours, iminutes,
iseconds, day-of-week, time-zone-offset)
= decode-date(date);
local method wrap0 (i :: <integer>) => (string :: <string>)
if (i < 10)
concatenate("0", integer-to-string(i));
else
integer-to-string(i)
end;
end;
concatenate(integer-to-string(iday), " ",
$month-names[imonth - 1], " ",
//integer-to-string(iyear), " ",
wrap0(ihours), ":",
wrap0(iminutes), ":",
wrap0(iseconds));
end;
define method print-xml (change :: <change>, #key base-url)
concatenate(print-xml(change.date),
list(with-xml()
text(concatenate(" by ", change.author, ": "))
end),
print-xml(change.command, base-url: base-url));
end;
define method print-change (change :: <change>, #key base-url)
concatenate(print-change(change.date), " by ", change.author, ": ",
print-change(change.command, base-url: base-url))
end;