8 let document heading extra x
=
9 html ~a
:[a_xmlns `W3_org_1999_xhtml
; a_xml_lang
"en"]
10 (head
(title
(t heading
)) extra
)
13 let doc heading x
= document heading
[] x
15 let input_text ~title
() =
16 form ~a
:[a_method `Post
] ~action
:(uri_of_string
"")
19 (p
[textarea ~rows
:20 ~cols
:80 ~a
:[a_name
"text"] (t"")]);
20 (p
[input ~a
:[a_name
"submit"; a_value
"Submit"; a_input_type `Submit
] ()]);
23 let ahref s
= a ~a
:[a_href
(uri_of_string s
)]
29 let arg x
= catch
(List.find
(fun a
-> a#name
= x
))
31 type location
= string
33 (* **************************** *)
37 let rec resolve self url
=
38 if url
= self#url
then self
39 else List.find
(fun child
-> try ignore
(resolve child url
); true with Not_found
-> false) self#children
43 method virtual url
: location
44 method virtual name
: string
45 method virtual children
: base list
46 method virtual render
: <name
:string;value:string> list
-> html
49 let header self pages
=
50 let name x
= if Oo.id x
= Oo.id self
then [b
[t x#
name]] else [t x#
name] in
51 div
[p
(List.map
(fun p
-> [ahref p#url
(name p
); space
()]) pages
>> List.flatten
); hr
()]
53 let render_markdown s
=
54 let module SM
= Simple_markup
in
55 let render_pre ~kind s
= t s
56 and render_link href
= ahref href
.SM.href_target
[t href
.SM.href_desc
]
57 and render_img i
= img ~src
:(uri_of_string i
.SM.img_src
) ~alt
:i
.SM.img_alt
() in
58 s
>> SM.parse_text
>> Simple_markup__html.to_html ~
render_pre ~render_link ~render_img
60 class comment ctx
= object(self
)
63 method url
= "/comment"
64 method name = z#add_comment
67 match arg "text" args
with
68 | Some
text -> text#
value >> render_markdown >> div
69 | None
-> div
[p
[t ""]]
75 input_text self#
name ()
82 method comment
= new comment self
83 method children
= ([self#comment
]:>base list
)
85 method name = z#main_page
90 ul (List.map
(fun x
-> li
[ahref x#url
[t x#
name]]) [self#comment
]);
101 method name = z#not_found
106 p
[t "Url "; b
[t url
]; t " not found."];