package eliom
Install
Dune Dependency
Authors
Maintainers
Sources
md5=c8c67fe5fb8d3f44a3b17cc4a93a0e62
sha512=e58557a1b525efd011e0eb539b112b53e6c012ac3fb2153c251be030eda483dd3b19de625707cf5ffebd97fa6a7fabfb8a6aae8e8a61c79e0bd7ad2d289df9a9
doc/eliom.server/Eliom_tools/index.html
Module Eliom_tools
Source
Helpers for (hierarchical) menu generation in HTML5. See the Eliom manual for more information about <<a_manual
chapter="misc" fragment="basic_menu"| menu>>
or <<a_manual
chapter="misc" fragment="hier_menu"| hierarchical site>>
.
type srv =
| Srv : (unit, unit, Eliom_service.get, _, _, _, _, [ `WithoutSuffix ], unit, unit, Eliom_service.non_ocaml) Eliom_service.t -> srv
Hierarchical sites description. This is a pair (main page, subpages list)
. Each subpage is defined by the text to be displayed in menus and a hierarchical_site_item
.
Menu entry description in a hierarchical site.
and main_page =
| Main_page of srv
(*Main page for your subsite: all the subpages are subsections of that page.
*)| Default_page of srv
(*Like
*)Main_page
but is not taken into account for computing which is the current page in the menu. Use it for example when there is no main page, but you want one of the subpages to be the default page for your subsite. The service you use as default page must appear another time in the subtree!| Not_clickable
(*When you do not want the menu entry to be a link but you want subpages.
*)
Main page description for a section of a hierarchical site.
Tools for generating certain HTML elements
Menus with functional node semantics
Menus with DOM semantics
Record an (external) JavaScript file to be included in Eliom_tools.F.html
.
Record an CSS file to be included in Eliom_tools.F.html
.
Other tools
val wrap_handler :
(unit -> 'a option Lwt.t) ->
('get -> 'post -> 'res Lwt.t) ->
('a -> 'get -> 'post -> 'res Lwt.t) ->
'get ->
'post ->
'res Lwt.t
This function allows one to wrap a service handler easily depending on whether certain information is available or not.
The first arguments provides that information (Some value
) of not (None
), the second argument is called just with two arguments when the information is not available (the two arguments are suggesting GET and POST parameters of a request). The third argument is called with that information if available and the parameters.
<<code language="ocaml"|
let user_eref = Eliom_reference.eref ~scope None
let anonymous_handler _ _ =
Lwt.return (html (head (title "not allowed")) (body []))
let authenticated_handler f =
Eliom_tools.wrap_handler
(fun () -> Eliom_reference.get user_eref)
anonymous_handler f
let guarded_service =
My_app.register_service ~path ~get_param
(authenticated_handler
(fun user get () ->
Lwt.return (html (head (title ("hello "^user))) (body []))))
>>