comparison src/demo.sml @ 381:1fe85b58c9ba

Generating urp HTML
author Adam Chlipala <adamc@hcoop.net>
date Sun, 19 Oct 2008 14:13:08 -0400
parents 758304561b60
children aa2edbd47041
comparison
equal deleted inserted replaced
380:758304561b60 381:1fe85b58c9ba
45 45
46 val fname = OS.Path.joinDirFile {dir = outDir, 46 val fname = OS.Path.joinDirFile {dir = outDir,
47 file = "index.html"} 47 file = "index.html"}
48 48
49 val out = TextIO.openOut fname 49 val out = TextIO.openOut fname
50 val () = (TextIO.output (out, "<frameset cols=\"15%,90%\">\n"); 50 val () = (TextIO.output (out, "<frameset cols=\"10%,90%\">\n");
51 TextIO.output (out, "<frame src=\"demos.html\">\n"); 51 TextIO.output (out, "<frame src=\"demos.html\">\n");
52 TextIO.output (out, "<frame src=\"intro.html\" name=\"staging\">\n"); 52 TextIO.output (out, "<frame src=\"intro.html\" name=\"staging\">\n");
53 TextIO.output (out, "</frameset>\n"); 53 TextIO.output (out, "</frameset>\n");
54 TextIO.closeOut out) 54 TextIO.closeOut out)
55 55
56 val fname = OS.Path.joinDirFile {dir = outDir, 56 val fname = OS.Path.joinDirFile {dir = outDir,
57 file = "demos.html"} 57 file = "demos.html"}
58 58
59 val demosOut = TextIO.openOut fname 59 val demosOut = TextIO.openOut fname
60 val () = (TextIO.output (demosOut, "<html><body><ul>\n\n"); 60 val () = (TextIO.output (demosOut, "<html><body>\n\n");
61 TextIO.output (demosOut, "<li> <a target=\"staging\" href=\"intro.html\">Intro</a></li>\n\n")) 61 TextIO.output (demosOut, "<li> <a target=\"staging\" href=\"intro.html\">Intro</a></li>\n\n"))
62 62
63 fun mergeWith f (o1, o2) = 63 fun mergeWith f (o1, o2) =
64 case (o1, o2) of 64 case (o1, o2) of
65 (NONE, _) => o2 65 (NONE, _) => o2
225 end 225 end
226 else 226 else
227 (TextIO.output (out, line); 227 (TextIO.output (out, line);
228 readIndex ()) 228 readIndex ())
229 end 229 end
230
231 fun prettyPrint () =
232 let
233 val dir = Posix.FileSys.opendir dirname
234
235 fun loop () =
236 case Posix.FileSys.readdir dir of
237 NONE => Posix.FileSys.closedir dir
238 | SOME file =>
239 let
240 fun doit f =
241 f (OS.Path.joinDirFile {dir = dirname,
242 file = file},
243 OS.Path.joinDirFile {dir = outDir,
244 file = OS.Path.joinBaseExt {base = file,
245 ext = SOME "html"}})
246 in
247 case OS.Path.ext file of
248 SOME "urp" =>
249 doit (fn (src, html) =>
250 let
251 val inf = TextIO.openIn src
252 val out = TextIO.openOut html
253
254 fun loop () =
255 case TextIO.inputLine inf of
256 NONE => ()
257 | SOME line => (TextIO.output (out, line);
258 loop ())
259 in
260 TextIO.output (out, "<html><head>\n<title>");
261 TextIO.output (out, file);
262 TextIO.output (out, "</title>\n</head><body>\n<h1>");
263 TextIO.output (out, file);
264 TextIO.output (out, "</h1>\n\n<pre>");
265 loop ();
266 TextIO.output (out, "</pre>\n\n</body></html>");
267
268 TextIO.closeIn inf;
269 TextIO.closeOut out
270 end)
271 | _ => ();
272 loop ()
273 end
274 in
275 loop ()
276 end
230 in 277 in
231 readIndex (); 278 readIndex ();
232 279
233 TextIO.output (demosOut, "\n</ul></body></html>\n"); 280 TextIO.output (demosOut, "\n</body></html>\n");
234 TextIO.closeOut demosOut 281 TextIO.closeOut demosOut;
282
283 prettyPrint ()
235 end 284 end
236 285
237 end 286 end