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

Contents of /web/site.cd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 713 - (show annotations)
Tue Jul 10 17:58:04 2007 UTC (5 years, 10 months ago) by abate
File size: 12135 byte(s)
[r2003-10-08 21:24:38 by cvscast] Separate compilation

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

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