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

Contents of /web/site.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1330 - (hide annotations)
Tue Jul 10 18:40:21 2007 UTC (5 years, 10 months ago) by abate
File size: 14945 byte(s)
[r2004-11-04 00:13:28 by beppe] Empty log message

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

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