Fix outstanding bugs
[pkg-ocaml-ocsigen.git] / examples / ocamlduce / exampleduce.ml
blobbf5490f241feb9684c7ad63738f2c30ee46011fe
1 (* Ocsigen
2 * Copyright (C) 2005 Vincent Balat
3 * Laboratoire PPS - CNRS Université Paris Diderot
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, with linking exception;
8 * either version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 open Eliom_services
22 open Eliom_parameters
23 open Eliom_sessions
24 open Eliom_duce.Xhtml
25 open Lwt
26 open Xhtmltypes_duce
28 let s =
29 register_new_service
30 ~path:[""]
31 ~get_params:unit
32 (fun sp () () ->
33 return
34 ({{ <html xmlns="http://www.w3.org/1999/xhtml">
35 [<head> [<title> ""]
36 <body> [<h1> "This page has been type checked by OcamlDuce"
37 ]] }} : {{ html }}))
39 let create_form =
40 (fun (number_name,(number2_name,string_name)) ->
41 {{ [ <p> [ 'Write an int: '
42 {{ int_input ~input_type:{{ "text" }} ~name:number_name () }}
43 'Write another int: '
44 {{ int_input ~input_type:{{ "text" }} ~name:number2_name () }}
45 'Write a string: '
46 {{ string_input ~input_type:{{ "text" }} ~name:string_name () }}
47 {{ string_input ~input_type:{{ "submit" }} ~value:"Click" ()}} ] ] }} )
49 let form = register_new_service ["form"] unit
50 (fun sp () () ->
51 let f = get_form Tutoeliom.coucou_params sp create_form in
52 return
53 {{ <html xmlns="http://www.w3.org/1999/xhtml">
54 [<head> [<title> ""]
55 <body> [ f ] ]}})
57 let links = register_new_service ["links"] unit
58 (fun sp () () -> return
59 {{ <html xmlns="http://www.w3.org/1999/xhtml">
60 [ <head> [<title> ""]
61 <body>
62 [<p>
63 [{{ a s sp {{ "first page" }} () }}
64 <br> []
65 {{ a form sp {{ "form" }} () }}
66 <br> []
67 (* {{ a s sp {{ "hello" }} () }}
68 <br> []
69 {{ a coucou_params sp
70 {{ "coucou_params" }} (42,(22,"ciao")) }}
71 <br> [] *)
72 {{ a
73 (new_external_service
74 ~prefix:"http://fr.wikipedia.org"
75 ~path:["wiki"]
76 ~get_params:(suffix (string "a"))
77 ~post_params:unit ())
79 {{ "ocaml on wikipedia" }}
80 "OCaml" }}]]] }})
85 let main = new_service ~path:["radio"] ~get_params:unit ()
86 let form =
87 new_post_service ~fallback:main ~post_params:(radio string "test") ()
89 let gen_form = fun x ->
90 {{ [<p>[
91 {: string_radio ~checked:false ~name:x ~value:"Blerp" () :}
92 'Blerp'
93 {: string_radio ~checked:false ~name:x ~value:"Gnarf" () :}
94 'Gnarf'
95 {: string_input ~input_type:{{ "submit" }} ~value:"OK" () :}
96 ]] }}
98 let _ =
99 register ~service:main
100 (fun sp () () ->
101 return {{ <html xmlns="http://www.w3.org/1999/xhtml">[
102 <head>[<title>"Main"]
103 <body>[{: post_form form sp gen_form () :}]
104 ] }}
106 register ~service:form
107 (fun sp () x ->
108 return {{ <html xmlns="http://www.w3.org/1999/xhtml">[
109 <head>[<title>"Form"]
110 <body>[<p>{: match x with None -> "Geen" | Some y -> y :}]
111 ] }})
115 let blocks =
116 Eliom_duce.Blocks.register_new_service
117 ~path:["blocks"]
118 ~get_params:unit
119 (fun sp () () ->
120 return
121 ({: [ <h1> "This page has been type checked by OcamlDuce"] :} ))