| 1 |
include "xhtml-strict.cd";;
|
| 2 |
include "xhtml-categ.cd";;
|
| 3 |
|
| 4 |
type Site = <site>[ <page {|input=String; output=String|}>[]* ];;
|
| 5 |
|
| 6 |
type Page = <page>[
|
| 7 |
<title>String
|
| 8 |
<banner>[InlineText*]
|
| 9 |
<navig>[ NavigBox* ] <main>[ Box* ] ];;
|
| 10 |
|
| 11 |
type Author = <author>String;;
|
| 12 |
type Paper =
|
| 13 |
<paper file=?String>[
|
| 14 |
<title>String
|
| 15 |
Author+
|
| 16 |
<comment>[InlineText*]
|
| 17 |
<abstract>Content ];;
|
| 18 |
type Slides =
|
| 19 |
<slides file=String>[
|
| 20 |
<title>String
|
| 21 |
Author+
|
| 22 |
<comment>[InlineText*]
|
| 23 |
];;
|
| 24 |
|
| 25 |
type Link =
|
| 26 |
<link url=String; title=String>[InlineText*];;
|
| 27 |
|
| 28 |
|
| 29 |
type Content =
|
| 30 |
[ ( <p {||}>[InlineText*]
|
| 31 |
| <ul {||}>[<li {||}>Content +]
|
| 32 |
| <section title=String>Content
|
| 33 |
| Paper | Slides | Link | InlineText )* ];;
|
| 34 |
|
| 35 |
type InlineText =
|
| 36 |
Char
|
| 37 |
| <(`b|`i) {||}>[InlineText*]
|
| 38 |
| Xa
|
| 39 |
| Ximg
|
| 40 |
;;
|
| 41 |
|
| 42 |
type Box = <box title=String; subtitle=?String; link=String>Content
|
| 43 |
| <meta>Content;;
|
| 44 |
type NavigBox = <box>Content | <toc>[];;
|
| 45 |
|
| 46 |
let fun authors ([Author+] -> String)
|
| 47 |
| [ <author>a ] -> a
|
| 48 |
| [ <author>a1 <author>a2 ] -> a1 @ ", and " @ a2
|
| 49 |
| [ <author>a; rem ] -> a @ ", " @ authors rem;;
|
| 50 |
|
| 51 |
let fun content (t : Content) : Flow =
|
| 52 |
transform t with
|
| 53 |
| <section title=title>c -> [ <h4>title !(content c) ]
|
| 54 |
| <paper (r)>[ <title>tit aut::Author* <comment>com <abstract>ab ] ->
|
| 55 |
[
|
| 56 |
(match r with
|
| 57 |
| { file = f } -> <a href=f>tit
|
| 58 |
| _ -> <b>tit
|
| 59 |
) '. '
|
| 60 |
!(authors aut) '. '
|
| 61 |
!com
|
| 62 |
<div class="abstract">[ 'Abstract:' !(content ab) ]
|
| 63 |
]
|
| 64 |
| <slides file=f>[ <title>tit aut::Author* <comment>com ] ->
|
| 65 |
[ <a href=f>tit '. ' !(authors aut) '. ' !com ]
|
| 66 |
| <link url=url; title=title>com ->
|
| 67 |
[ <a href=url>title '. ' !com ]
|
| 68 |
| <ul>lis -> [ <ul>(map lis with <li>x -> <li>(content x)) ]
|
| 69 |
| x -> [ x ];;
|
| 70 |
|
| 71 |
let fun main2html (Box -> Flow)
|
| 72 |
<box (r)>c ->
|
| 73 |
[ <div class="box">[
|
| 74 |
<h2>(r.title)
|
| 75 |
!(match r with { subtitle = t } -> [<b>t] | _ -> [])
|
| 76 |
<a name=r.link>[]
|
| 77 |
!(content c) ] ]
|
| 78 |
| <meta>c -> [ <div class="meta">(content c) ];;
|
| 79 |
|
| 80 |
|
| 81 |
let fun page2html (Page -> Xhtml)
|
| 82 |
<page>[ <title>title <banner>banner <navig>navig <main>main ] ->
|
| 83 |
let toc =
|
| 84 |
transform main with <box title=t; link=l>_ -> [ <li>[ <a href=('#',l)>t ] ] in
|
| 85 |
let toc = match toc with [] -> [] | lis -> [ <ul>lis ] in
|
| 86 |
let navig : Flow = transform navig with
|
| 87 |
| <box>c -> [ <div class="box">(content c) ]
|
| 88 |
| <toc>[] -> [ <div class="box">toc ]
|
| 89 |
in
|
| 90 |
<html>[
|
| 91 |
<head>[
|
| 92 |
<title>title
|
| 93 |
<meta content="text/html; charset=iso-8859-1"; http-equiv="Content-Type">[]
|
| 94 |
<link rel="stylesheet"; href="cduce.css"; type="text/css"> []
|
| 95 |
]
|
| 96 |
<body>[
|
| 97 |
<div class="title">[ <h1>banner ]
|
| 98 |
<div id="Sidelog">navig
|
| 99 |
<div id="Content">(transform main with b -> main2html b)
|
| 100 |
]
|
| 101 |
];;
|
| 102 |
|
| 103 |
let fun do_page((String,String) -> [])
|
| 104 |
(inf,outf) ->
|
| 105 |
let _ = print [ 'Loading ' !inf '... ' ] in
|
| 106 |
let page = match load_xml inf with
|
| 107 |
| Page & p -> p
|
| 108 |
| _ -> raise ("Invalid input document" @ inf) in
|
| 109 |
let _ = print [ 'Generating html ... ' ] in
|
| 110 |
let html : String =
|
| 111 |
[ '<?xml version="1.0" encoding="iso-8859-1"?>'
|
| 112 |
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
|
| 113 |
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
| 114 |
!(print_xml (page2html page)) ] in
|
| 115 |
let _ = print [ 'Saving to ' !outf '...\n' ] in
|
| 116 |
dump_to_file outf html;;
|
| 117 |
|
| 118 |
|
| 119 |
let site =
|
| 120 |
let _ = print [ 'Loading site.xml ...\n' ] in
|
| 121 |
match load_xml "site.xml" with
|
| 122 |
| Site & <site>s ->
|
| 123 |
(transform s with <page input=inf; output=outf>[] ->
|
| 124 |
do_page(inf,outf))
|
| 125 |
| _ -> raise "Invalid site.xml";;
|