/[svn]/web/site.cd
ViewVC logotype

Contents of /web/site.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1064 - (hide annotations)
Tue Jul 10 18:20:16 2007 UTC (5 years, 10 months ago) by abate
File size: 13677 byte(s)
[r2004-04-13 13:49:40 by afrisch] Update website

Original author: afrisch
Date: 2004-04-13 13:49:40+00:00
1 abate 284 (* This CDuce script produces CDuce web site. *)
2    
3 abate 369 (** Command line **)
4    
5 abate 580 let input =
6 abate 369 match argv with
7 abate 580 | [ s ] -> s
8 abate 709 | _ -> raise "Please use --arg to specify an input file on the command line"
9 abate 369
10 abate 343 (** Output types **)
11 abate 284
12 abate 713 using H = "xhtml"
13 abate 250
14 abate 343 (** Input types **)
15    
16 abate 1064 type Page = <page name=String new=?"">[ <title>String <banner>[InlineText*]? Item* ]
17 abate 488 type External = <external {|href=String; title=String; name=String |}>[]
18 abate 343
19     type Item =
20 abate 777 <box noindex=?String title=String link=String>Content
21 abate 343 | <meta>Content
22     | <left>Content
23 abate 1064 | <footnotes>[]
24 abate 343 | Page
25 abate 488 | External
26 abate 343
27 abate 488 type Author = <author>String
28 abate 343 type Paper =
29 abate 1064 <paper file=?String old=?"">[
30 abate 488 <title>String Author+ <comment>[InlineText*] <abstract>Content ]
31 abate 343
32     type Slides =
33 abate 488 <slides file=String>[ <title>String Author+ <comment>[InlineText*] ]
34 abate 343
35     type Link =
36 abate 561 <link url=String title=String>[ InlineText* ]
37 abate 343
38     type Content =
39 abate 614 [ ( <p {|style=?String|}>[InlineText*]
40 abate 1064 | <ul {||}>[<li {||}>Content *]
41 abate 343 | <section title=String>Content
42 abate 344 | <sample highlight=?"true"|"false">String
43 abate 979 | <xmlsample highlight=?"true"|"false">String
44 abate 981 | <sessionsample highlight=?"true"|"false">String
45 abate 713 | H:Xtable
46 abate 343 | Paper | Slides | Link
47 abate 1064 | <boxes-toc sections=?"">[] (* the optional "section" produces *)
48     | <pages-toc sections=?"">[] (* a two-level toc *)
49 abate 343 | <site-toc>[]
50     | <local-links href=String>[]
51 abate 356 | <two-columns>[ <left>Content <right>Content ]
52 abate 976 | <note> Content
53 abate 1064 | <footnotes>[]
54 abate 343 | InlineText
55 abate 488 )* ]
56 abate 343
57     type InlineText =
58     Char
59 abate 593 | <(`b|`i|`tt|`em) {| style=?String |}>[InlineText*]
60 abate 343 | <code>String
61 abate 347 | <local href=String>String
62 abate 625 | <footnote>[InlineText*]
63 abate 713 | H:Xa | H:Ximg | H:Xbr
64 abate 343
65     (** Generic purpose functions **)
66    
67     (* Recursive inclusion of XML files and verbatim text files *)
68    
69 abate 488 let load_include (String -> [Any*])
70 abate 336 name ->
71 abate 368 (* let _ = print [ 'Loading ' !name '... \n' ] in *)
72 abate 336 xtransform [ (load_xml name) ] with
73 abate 341 | <include file=(s & String)>[] -> load_include s
74 abate 488 | <include-verbatim file=(s & String)>[] -> load_file s
75 abate 336
76 abate 343 (* Highlighting text between {{...}} *)
77 abate 336
78 abate 981 let highlight (String -> [ (Char | H:Xstrong | H:Xi)* ] )
79     | [ '{{%%' h ::(Char *?) '%%}}' ; rest ] ->
80     [ <strong class="highlight">[<i>h]; highlight rest ]
81 abate 340 | [ '{{' h ::(Char *?) '}}' ; rest ] ->
82 abate 981 [ <strong class="highlight">h; highlight rest ]
83 abate 1037 | [ '$$%%' h ::(Char *?) '%%$$' ; rest ] ->
84     [ <strong class="ocaml">[<i>h]; highlight rest ]
85     | [ '$$' h ::(Char *?) '$$' ; rest ] ->
86     [ <strong class="ocaml">h; highlight rest ]
87 abate 381 | [ '%%' h ::(Char *?) '%%' ; rest ] ->
88 abate 698 [ <i>h; highlight rest ]
89 abate 340 | [ c; rest ] -> [ c; highlight rest ]
90 abate 488 | [] -> []
91 abate 336
92 abate 343 (* Split a comma-separated string *)
93    
94 abate 488 let split_comma (String -> [String*])
95 abate 341 | [ x::(Char*?) ',' ; rest ] -> (x, split_comma rest)
96 abate 488 | s -> [ s ]
97 abate 336
98 abate 253
99 abate 343 (** Internal types **)
100 abate 341
101 abate 488 type Path = [ { url = String; title = String }* ]
102 abate 341 type Tree = { name = String; url = String; title = String;
103 abate 1058 children = [Tree*]; boxes = [H:Xul?] }
104 abate 250
105 abate 488 let url_of_name (String -> String)
106 abate 1064 | "index" -> "/"
107 abate 488 | s -> s @ ".html"
108 abate 346
109 abate 488 let authors ([Author+] -> String)
110 abate 1064 | [ <author>a ] -> a
111     | [ <author>a1 <author>a2 ] -> a1 @ ", and " @ a2
112     | [ <author>a; rem ] -> a @ ", " @ authors rem
113 abate 250
114 abate 488 let find_local_link (sitemap : [Tree*], l : String) : Tree =
115 abate 341 match sitemap with
116     | (h,t) ->
117 abate 347 if (h . name = l) then h
118 abate 341 else
119     (try find_local_link (t,l) with `Not_found ->
120     find_local_link (h . children,l))
121 abate 488 | [] -> raise `Not_found
122 abate 341
123 abate 713 let local_link (sitemap : Tree, l : String, txt : String) : H:Inline =
124 abate 347 try
125     let h = find_local_link ([sitemap],l) in
126     let txt = if txt = "" then h . title else txt in
127     <a href=(h . url)>txt
128 abate 488 with `Not_found -> raise [ 'Local link not found: ' !l ]
129 abate 341
130 abate 488 let compute_sitemap ((Page|External) -> Tree)
131 abate 1064 | <page name=name>[ <title>title (c::(Page|External) | _)* ] & p ->
132 abate 341 let children = map c with p -> compute_sitemap p in
133 abate 1058 { name = name; url = (url_of_name name); title = title;
134     children = children; boxes = (boxes_of p) }
135 abate 1064 | <external name=name href=h title=t>[] ->
136 abate 1058 { name = name; url = h; title = t; children = []; boxes = [] }
137 abate 341
138 abate 1064 let ul([H:Xli*] -> [H:Xul?]) [] -> [] | l -> [ <ul>l ]
139    
140 abate 713 let display_sitemap (h : Tree) : H:Xli =
141 abate 341 let ch = map h . children with x -> display_sitemap x in
142 abate 1064 <li>[ <a href=(h . url)>[ '[' !(h . title) ']' ] !(h . boxes); (ul ch) ]
143 abate 341
144 abate 681
145 abate 1064 let boxes_of (Page -> [H:Xul?])
146     <page name=n>[ (items::Item | _)*] ->
147     let toc = transform items with
148     | <box noindex="">_ -> []
149     | <box title=t link=l>_ -> [ <li>[ <a href=[ !(url_of_name n) '#' !l ]>t ] ]
150     in
151     ul toc
152 abate 351
153 abate 1064 let link_to (<page name=n>[<title>t ; _ ] & p : Page) : H:Xa =
154     let t = match p with
155     | <_ new="">_ -> t @ [ <img src="img/new.gif" alt="(new)" style="border:0">[]]
156     | _ -> t in
157     <a href=(url_of_name n)>t
158    
159 abate 713 let box (x : H:Flow) : H:Block =
160 abate 580 <table cellpadding="2"
161 abate 586 style="font-size:11px ; font-family:arial,sans-serif;
162     border: solid 2px black; background: #ffffff" width="100%">
163 abate 580 [ <tr> [<td>x] ]
164    
165 abate 713 let meta (x : H:Flow) : H:Block =
166 abate 580 <table cellpadding="2"
167 abate 797 style="border: solid 1px #b0b0b0; background: #e0e0e0; font-size: 80%"
168 abate 580 width="100%">
169     [ <tr> [<td>x] ]
170    
171 abate 1058 let box_title (x : H:Flow, a : String, t : String) : H:Block =
172 abate 580 <table cellpadding="5"
173     style="border: solid 2px black; background: #ffffff" width="100%">
174 abate 1058 [ <tr>[
175     <td style="background: #fff0f0; color: #0000ff; font: bold 100%
176     helvetica">[<a name=a>t] ]
177     <tr> [<td>x] ]
178 abate 580
179     let style = "
180     a:link:hover, a:visited:hover {
181     text-decoration: none;
182     background: #FFFFD0;
183     color: #FF0000;
184     }
185 abate 1064 a.old, a.old:hover, a.old:visited:hover { text-decoration: line-through; }
186     p { text-align: justify; margin: 1ex 1em 0 1em; }
187     pre { margin: 1ex 1em 0 1em; }
188     strong.ocaml{ color: #333b8e; }
189     strong.highlight { color: #FF0000; }
190     img.icon { border: 0; }
191     div.code { background: #E0E0E0; margin: 0.5ex 0.5em 0 0.5em; padding: 0.2ex; }
192     div.xmlcode { background:#ebefa2; margin: 0.5ex 0.5em 0 0.5em; padding: 0.2ex;}
193 abate 976
194 abate 580 div.abstract {
195 abate 736 font: bold helvetica;
196 abate 580 margin: 1ex 1em 1ex 1em;
197     padding: 1ex 1em 1ex 1em;
198     background: #F0F0F0;
199     }
200 abate 976
201     div.note {
202 abate 979 text-align: justify;
203 abate 976 font: bold helvetica;
204     margin: 1ex 3em 1ex 3em;
205     padding: 1ex 1em 1ex 1em;
206     background: #D0E2D2;
207     }
208    
209 abate 981 div.session
210     {
211     font: bold 80% helvetica;
212     margin: 1ex 1em 1ex 1em;
213     padding: 1ex 1em 1ex 1em;
214     border: solid .5px grey;
215     }
216    
217 abate 1064 div.abstract p { font: sans-serif; }
218 abate 580 "
219    
220 abate 1064 type PageO = Page | []
221    
222 abate 343 (* Main transformation function *)
223    
224 abate 386 (* returns the last page of the descendance *)
225 abate 1064 let gen_page (prev : PageO, page : Page, next : PageO,
226     path : Path, sitemap : Tree) : PageO =
227     match page with
228 abate 381 <page name=name>[
229 abate 1064 <title>title <banner>banner | <title>(title & banner); items ] ->
230 abate 341
231 abate 625 let footnote_counter = ref Int 0 in
232 abate 713 let footnotes = ref H:Flow [] in
233 abate 625
234 abate 713 let text (t : [InlineText*]) : H:Inlines =
235 abate 625 transform t with
236     | <code>x -> [ <b>[ <tt>(highlight x) ] ]
237     | <local href=l>txt -> [ (local_link (sitemap,l,txt)) ]
238     | <(tag & (`b|`i|`tt|`em)) (attr)>x -> [ <(tag) (attr)>(text x) ]
239     | <footnote>c ->
240     footnote_counter := !footnote_counter + 1;
241     let n = string_of !footnote_counter in
242     let fn = !footnotes in
243     footnotes := [];
244     let c = <p>[ <a name=[ 'note' !n ]>[]
245     <a href=[ '#bnote' !n ]>[ '[' !n ']' ]
246     ' ' ; text c ] in
247     footnotes := fn @ [ c ] @ !footnotes;
248     [ <a name=[ 'bnote' !n ]>[]
249     <a href=[ '#note' !n ]>[ '[' !n ']' ] ]
250 abate 698 | z -> [ z ]
251 abate 341 in
252 abate 254
253 abate 713 let content (t : Content) : H:Flow =
254 abate 250 transform t with
255 abate 284 | <section title=title>c ->
256 abate 580 [ <p>[ <b style="color: #008000">title ] !(content c) ]
257 abate 250 | <paper (r)>[ <title>tit aut::Author* <comment>com <abstract>ab ] ->
258 abate 734 [ (match r with
259 abate 1064 | { file = f; old = "" } -> <a class="old" href=f>tit
260 abate 734 | { file = f } -> <a href=f>tit
261     | _ -> <b>tit) '. '
262 abate 250 !(authors aut) '. '
263 abate 254 !(text com)
264 abate 250 <div class="abstract">[ 'Abstract:' !(content ab) ]
265     ]
266     | <slides file=f>[ <title>tit aut::Author* <comment>com ] ->
267 abate 254 [ <a href=f>tit '. ' !(authors aut) '. ' !(text com) ]
268 abate 344 | <sample highlight="false">s ->
269     [ <div class="code">[ <pre>s ] ]
270 abate 336 | <sample>s ->
271 abate 340 [ <div class="code">[ <pre>(highlight s) ] ]
272 abate 979 | <xmlsample highlight="false">s ->
273     [ <div class="xmlcode">[ <pre>s ] ]
274     | <xmlsample>s ->
275     [ <div class="xmlcode">[ <pre>(highlight s) ] ]
276 abate 981 | <sessionsample highlight="false">s ->
277     [ <div class="session">[ <pre>s ] ]
278     | <sessionsample>s ->
279     [ <div class="session">[ <pre>(highlight s) ] ]
280 abate 561 | <link url=url title=title>com ->
281 abate 284 [ <a href=url>title '. ' !(text com) ]
282     | <ul>lis ->
283 abate 1064 ul (map lis with <li>x -> <li>(content x))
284 abate 713 | H:Xtable & x ->
285 abate 284 [ x ]
286 abate 614 | <p (attr)>x -> [ <p (attr)>(text x) ]
287 abate 681 | <pages-toc (a)>[] ->
288 abate 1064 let toc = transform items with
289     | Page & p ->
290     let sects = match a with {|sections=_|} -> boxes_of p | _ -> [] in
291     [ <li>[ (link_to p) ; sects ] ]
292     | <external href=l title=t>[] -> [ <li>[ <a href=l>t ] ] in
293     ul toc
294 abate 696 | <boxes-toc (a)>[] ->
295 abate 1064 let toc = transform items with
296     | <box noindex=_>_ -> []
297     | <box title=t link=l>b ->
298     let sects = match a with
299     | {|sections=_|} ->
300     (transform b with <section title=t>_ -> [<br>[] '-' !t])
301     | _ -> [] in
302     [ <li>[ <a href=('#',l)>t !sects ]] in
303     ul toc
304 abate 341 | <site-toc>[] ->
305     [ <ul>[ (display_sitemap sitemap) ] ]
306     | <local-links href=s>[] ->
307 abate 1064 ul (map (split_comma s) with x -> <li>[ (local_link(sitemap,x,"")) ])
308 abate 356 | <two-columns>[ <left>x <right>y ] ->
309     [ <table width="100%">[
310     <tr>[
311     <td valign="top">(content x)
312     <td valign="top">(content y) ] ] ]
313 abate 1064 | <note>c -> [ <div class="note">[ <b>"Note: " !(content c) ]]
314     | <footnotes>[] ->
315     (match !footnotes with
316     | [] -> []
317     | n -> footnotes := []; [ <br>[] (meta n) ] )
318 abate 341 | t -> text [ t ]
319     in
320 abate 250
321 abate 580 (* Preparing left panel *)
322 abate 698
323 abate 580 let navig = transform items with <left>c -> [ c ] in
324     let left = match navig with [] -> [ [<boxes-toc>[]] ] | n -> n in
325     let left =
326     <td valign="top" align="left">[
327 abate 589 <table cellpadding="0" cellspacing="15"
328 abate 586 width="200"
329     style="font-size:80%; border: 1px dashed black;
330 abate 797 background: #ffcd72"> (* altbg 9aa8ba *)
331 abate 580 (map left with x -> <tr>[ <td>[ (box (content x)) ] ]) ] in
332    
333 abate 713 let dpath : H:Inlines = transform path with
334 abate 391 | { url = f; title = t } -> [ <a href=f>t ': ']
335 abate 341 in
336 abate 625 let npath = path @ [ { url = (url_of_name name); title = title } ] in
337 abate 351 let subpages = transform items with p & Page -> [ p ] in
338 abate 386 let (next,last) = gen_page_seq (page, subpages, next, npath, sitemap) in
339 abate 391 let next = match next with [] -> []
340     | <page name=n>[ <title>t; _ ] ->
341     [ <a href=(url_of_name n)>[
342 abate 595 <img width="16" height="16" class="icon" alt="Next page:"
343 abate 586 src="img/right.gif">[]
344 abate 391 ' ' !t
345     ] ] in
346     let prev = match prev with [] -> []
347     | <page name=n>[ <title>t; _ ] ->
348     [ <a href=(url_of_name n)>[
349 abate 586 <img width="16" height="16" class="icon"
350 abate 595 alt="Previous page:" src="img/left.gif">[]
351 abate 391 ' ' !t
352     ] ] in
353 abate 580 let navig =
354 abate 391 if prev = [] then [] else
355 abate 580 [ (box [
356 abate 391 <p>[ !dpath !title ]
357 abate 580 <p>[ !prev ' ' !next ] ]) ] in
358    
359     (* Preparing main panel *)
360     let main = transform items with
361 abate 1058 | <box (r)>c -> [ (box_title (content c, r . link, r . title)) ]
362 abate 1064 | <footnotes>[] ->
363     (match !footnotes with
364     | [] -> []
365     | n -> footnotes := []; [ (meta n) ] )
366 abate 1058 | <meta>c -> [ (meta (content c)) ]
367 abate 580 in
368 abate 625 let notes = match !footnotes with
369     | [] -> []
370     | n -> [ (meta n) ] in
371     let main = match (navig @ main @ notes @ navig) with
372 abate 580 | [] -> raise "Empty page !"
373     | x -> x in
374    
375 abate 713 let right : H:Xtd =
376 abate 580 <td valign="top" align="left" style="width:100%">[
377     <table width="100%">[
378     <tr>[ <td valign="top" align="left"
379     style="border: 2px solid black; background: #ffffff;
380     text-align:center; color: #aa0000; font: bold 200% helvetica" >
381     (text banner)
382     ]
383    
384     <tr>[
385     <td valign="top" align="left"
386 abate 797 style="border: 1px solid black; background: #fccead">[ (* altbg c8ccd1 *)
387 abate 589 <table width="100%" cellpadding="0" cellspacing="17">
388 abate 580 (map main with x -> <tr>[ <td>[x] ])
389     ] ]
390     ] ] in
391    
392 abate 713 let html : H:Xhtml =
393 abate 250 <html>[
394     <head>[
395 abate 350 <title>[ 'CDuce: ' !title ]
396 abate 561 <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">[]
397 abate 580 <style type="text/css">style
398 abate 250 ]
399 abate 797 <body style="margin: 0; padding : 0; background: #fcb333">[ (* altbg 4e6e99 *)
400 abate 580 <table cellspacing="10" cellpadding="0" width="100%" border="0">[
401     <tr>[ left right ]
402     ]
403 abate 250 ]
404 abate 341 ]
405     in
406 abate 391 let txt : Latin1 =
407 abate 351 [ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
408 abate 341 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
409 abate 580 !(print_xml html) ] in
410     let fn = "www/" @ name @ ".html" in
411 abate 625 dump_to_file fn txt;
412 abate 488 last
413 abate 386
414 abate 250
415 abate 488 let gen_page_seq
416 abate 1064 (prev : PageO, pages : [Page*], next : PageO,
417     path : Path, sitemap : Tree) : (PageO, PageO) =
418 abate 351 match pages with
419     | [ p1 p2 ; _ ] & [ _; rest ] ->
420 abate 386 let last = gen_page (prev,p1,p2, path, sitemap) in
421     let (_,last) = gen_page_seq (last, rest, next, path, sitemap) in
422     (p1,last)
423 abate 351 | [ p ] ->
424 abate 386 let last = gen_page (prev,p,next, path, sitemap) in (p,last)
425 abate 488 | [] -> (next,prev)
426 abate 351
427    
428 abate 488 ;;
429 abate 284
430 abate 369 match load_include input with
431 abate 386 | [ Page & p ] -> let _ = gen_page ([],p,[], [], compute_sitemap p) in []
432 abate 488 | _ -> raise ("Invalid input document " @ input)
433 abate 369
434 abate 698

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5