annotate demo/more/versioned1.ur @ 1283:b04354e24d1b

ML-style comments inside XML
author Adam Chlipala <adam@chlipala.net>
date Tue, 10 Aug 2010 14:44:26 -0400
parents 166ea3944b91
children e6bc6bbd7a32
rev   line source
adamc@993 1 open Versioned.Make(struct
adamc@993 2 con key = [Id = int]
adamc@993 3 con data = [Nam = string, ShoeSize = int]
adamc@993 4
adamc@993 5 val key = {Id = _}
adamc@993 6 val data = {Nam = {Inj = _,
adamc@993 7 Eq = _},
adamc@993 8 ShoeSize = {Inj = _,
adamc@993 9 Eq = _}}
adamc@993 10 end)
adamc@993 11
adamc@995 12 fun retro vr =
adamc@995 13 ks <- keysAt vr;
adamc@995 14 ks <- List.mapM (fn r => fso <- archive vr r; return (r.Id, fso)) ks;
adamc@995 15
adamc@995 16 return <xml><body>
adamc@995 17 {List.mapX (fn (k, r) => <xml><li>
adamc@995 18 {[k]}: {case r of
adamc@995 19 None => <xml>Whoa!</xml>
adamc@995 20 | Some r => <xml>{[r.Nam]}, {[r.ShoeSize]}</xml>}
adamc@995 21 </li></xml>) ks}
adamc@995 22 </body></xml>
adamc@995 23
adamc@993 24 fun expandKey k =
adamc@993 25 name <- source "";
adamc@993 26 shoeSize <- source "";
adamc@993 27 return {Key = k, Nam = name, ShoeSize = shoeSize}
adamc@993 28
adamc@993 29 fun main () =
adamc@993 30 ks0 <- keys;
adamc@993 31 ks0 <- List.mapM (fn r => expandKey r.Id) ks0;
adamc@993 32 ks <- source ks0;
adamc@993 33
adamc@993 34 id <- source "";
adamc@993 35 name <- source "";
adamc@993 36 shoeSize <- source "";
adamc@993 37
adamc@995 38 times <- updateTimes;
adamc@995 39
adamc@993 40 return <xml><body>
adamc@993 41 <dyn signal={ks <- signal ks;
adamc@993 42 return (List.mapX (fn kr => <xml><div>
adamc@993 43 {[kr.Key]}:
adamc@993 44 <ctextbox source={kr.Nam}/>
adamc@993 45 <ctextbox size={5} source={kr.ShoeSize}/>
adamc@993 46 <button value="Latest" onclick={ro <- rpc (current {Id = kr.Key});
adamc@993 47 case ro of
adamc@993 48 None => alert "Can't get it!"
adamc@993 49 | Some r =>
adamc@993 50 set kr.Nam r.Nam;
adamc@993 51 set kr.ShoeSize (show r.ShoeSize)}/>
adamc@993 52 <button value="Update" onclick={name <- get kr.Nam;
adamc@993 53 shoeSize <- get kr.ShoeSize;
adamc@993 54 rpc (update {Id = kr.Key,
adamc@993 55 Nam = name,
adamc@993 56 ShoeSize = readError shoeSize})
adamc@993 57 }/>
adamc@993 58 </div></xml>) ks)}/>
adamc@993 59
adamc@993 60 <h2>Add one:</h2>
adamc@993 61
adamc@993 62 <table>
adamc@993 63 <tr><th>Id:</th> <td><ctextbox size={5} source={id}/></td></tr>
adamc@993 64 <tr><th>Name:</th> <td><ctextbox source={name}/></td></tr>
adamc@993 65 <tr><th>Shoe size:</th> <td><ctextbox size={5} source={shoeSize}/></td></tr>
adamc@993 66 <tr><th><button value="Add" onclick={id <- get id;
adamc@993 67 name <- get name;
adamc@993 68 shoeSize <- get shoeSize;
adamc@993 69 rpc (insert {Id = readError id, Nam = name,
adamc@993 70 ShoeSize = readError shoeSize});
adamc@993 71
adamc@993 72 cur <- get ks;
adamc@993 73 kr <- expandKey (readError id);
adamc@993 74 set ks (kr :: cur)}/></th></tr>
adamc@993 75 </table>
adamc@995 76
adamc@995 77 <h2>Archive</h2>
adamc@995 78
adamc@995 79 {List.mapX (fn (vr, tm) => <xml><li><a link={retro vr}>{[tm]}</a></li></xml>) times}
adamc@993 80 </body></xml>