diff --git a/template.distillery/PROJECT_NAME.eliom b/template.distillery/PROJECT_NAME.eliom index 6efff47e..56ab16a8 100644 --- a/template.distillery/PROJECT_NAME.eliom +++ b/template.distillery/PROJECT_NAME.eliom @@ -72,7 +72,7 @@ let%server _ = (* The modules below are all the modules that needs to be explicitely linked-in. *) -[%%server.start] +[%%shared.start] module Demo = Demo module Demo_cache = Demo_cache @@ -98,6 +98,5 @@ module Demo_users = Demo_users [%%client.start] -module Demo = Demo module %%%MODULE_NAME%%%_config = %%%MODULE_NAME%%%_config module %%%MODULE_NAME%%%_language = %%%MODULE_NAME%%%_language diff --git a/template.distillery/PROJECT_NAME_services.eliom b/template.distillery/PROJECT_NAME_services.eliom index 041a4ad8..76300b7d 100644 --- a/template.distillery/PROJECT_NAME_services.eliom +++ b/template.distillery/PROJECT_NAME_services.eliom @@ -9,10 +9,6 @@ let%server upload_user_avatar_service : (unit, unit) Ot_picture_uploader.service = Ot_picture_uploader.mk_service "upload_user_avatar_service" [%json: unit] -let%server demo_service = - Eliom_service.create ~path:(Eliom_service.Path ["demo"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - let%server settings_service = Eliom_service.create ~path:(Eliom_service.Path ["settings"]) ~meth:(Eliom_service.Get Eliom_parameter.unit) () diff --git a/template.distillery/demo.eliom b/template.distillery/demo.eliom index a4d96dd7..771dd124 100644 --- a/template.distillery/demo.eliom +++ b/template.distillery/demo.eliom @@ -18,24 +18,5 @@ let%shared handler myid_o () () = ; p [%i18n Demo.intro_3] ] let%shared () = - let registerDemo (module D : Demo_tools.Page) = - %%%MODULE_NAME%%%_base.App.register ~service:D.service - ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> - let%lwt p = D.page () in - %%%MODULE_NAME%%%_container.page ~a:[a_class [D.page_class]] myid_o p ) - in - List.iter registerDemo Demo_tools.demos; - %%%MODULE_NAME%%%_base.App.register ~service:%%%MODULE_NAME%%%_services.demo_service + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo (%%%MODULE_NAME%%%_page.Opt.connected_page handler) - -(* [detail_page_handler] is not registered in [Demo_tools] because we - - don't want to show detail pages in the menu. *) -let%shared () = - let detail_page_handler myid_o page () = - %%%MODULE_NAME%%%_container.page - ~a:[a_class ["os-page-demo-transition"]] - myid_o - (Demo_pagetransition.make_detail_page page ()) - in - %%%MODULE_NAME%%%_base.App.register ~service:Demo_pagetransition.detail_page_service - (%%%MODULE_NAME%%%_page.Opt.connected_page detail_page_handler) diff --git a/template.distillery/demo_cache.eliom b/template.distillery/demo_cache.eliom index 1a0d7582..c5bbc26f 100644 --- a/template.distillery/demo_cache.eliom +++ b/template.distillery/demo_cache.eliom @@ -4,20 +4,6 @@ (* Eliom_cscache demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-cache"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.cache] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-cache" - (* Page for this demo *) let%shared page () = Lwt.return @@ -29,3 +15,13 @@ let%shared page () = ~os_user_proxy:[code [txt "Os_user_proxy"]]] ; p [%i18n Demo.cache_3 ~eliom_cscache:[code [txt "Eliom_cscache"]]] ; p [%i18n Demo.cache_4 ~eliom_cscache:[code [txt "Eliom_cscache"]]] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_cache + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-cache"]] myid_o p ) diff --git a/template.distillery/demo_calendar.eliom b/template.distillery/demo_calendar.eliom index 52c76b4d..c4a05387 100644 --- a/template.distillery/demo_calendar.eliom +++ b/template.distillery/demo_calendar.eliom @@ -4,14 +4,6 @@ (* Calendar demo *) open Eliom_content.Html.D] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-calendar"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - (* A reactive value containing the currently selected date *) (* NOTE: in this example, we define a shared signal on the server side. Its original value can only be read when the server generates the first page @@ -45,12 +37,6 @@ let%server date_as_string () : string Eliom_shared.React.S.t = let%rpc date_reactive () : string Eliom_shared.React.S.t Lwt.t = Lwt.return @@ date_as_string () -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.calendar] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-calendar" - (* Page for this demo *) let%shared page () = let calendar = @@ -62,3 +48,13 @@ let%shared page () = ; p [%i18n Demo.this_page_show_calendar] ; div ~a:[a_class ["os-calendar"]] [calendar] ; p [Eliom_content.Html.R.txt dr] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_calendar + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-calendar"]] myid_o p ) diff --git a/template.distillery/demo_carousel1.eliom b/template.distillery/demo_carousel1.eliom index bae44972..fda89ae4 100644 --- a/template.distillery/demo_carousel1.eliom +++ b/template.distillery/demo_carousel1.eliom @@ -6,20 +6,6 @@ open Eliom_content.Html] [%%shared open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel1"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.carousel_1] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-carousel1" - (* Bind arrow keys *) let%shared bind_keys (change : ([`Goto of int | `Next | `Prev] -> unit) Eliom_client_value.t) @@ -78,3 +64,13 @@ let%shared page () = ~a:[a_class ["demo-carousel1"]] [div ~a:[a_class ["demo-carousel1-box"]] [carousel; prev; next; bullets]] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_carousel1 + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-carousel1"]] myid_o p ) diff --git a/template.distillery/demo_carousel2.eliom b/template.distillery/demo_carousel2.eliom index bdc4e5d1..e4a1604c 100644 --- a/template.distillery/demo_carousel2.eliom +++ b/template.distillery/demo_carousel2.eliom @@ -20,20 +20,6 @@ let%shared lorem_ipsum = "Amicitiam autem adhibendam esse censent, quia sit ex eo genere, quae prosunt. Hoc loco tenere se Triarius non potuit. Facile est hoc cernere in primis puerorum aetatulis. Sed in rebus apertissimis nimium longi sumus. Utrum igitur tibi litteram videor an totas paginas commovere? Quid de Platone aut de Democrito loquar?" ] ] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel2"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.carousel_2] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-carousel2" - (* Page for this demo *) let%shared page () = let make_page name = @@ -93,3 +79,13 @@ let%shared page () = ; div ~a:[a_class ["demo-carousel2"]] [div ~a:[a_class ["demo-carousel2-box"]] [tabs; carousel]] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_carousel2 + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-carousel2"]] myid_o p ) diff --git a/template.distillery/demo_carousel3.eliom b/template.distillery/demo_carousel3.eliom index 82d47246..9f6adaa9 100644 --- a/template.distillery/demo_carousel3.eliom +++ b/template.distillery/demo_carousel3.eliom @@ -6,20 +6,6 @@ open Eliom_content.Html] [%%shared open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel3"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.carousel_wheel] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-carousel3" - (* Page for this demo *) let%shared page () = let carousel_pages = @@ -86,3 +72,13 @@ let%shared page () = ~change ~pos ~vis_elts:(Eliom_shared.React.S.const 1) ~length [] ] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_carousel3 + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-carousel3"]] myid_o p ) diff --git a/template.distillery/demo_i18n.eliom b/template.distillery/demo_i18n.eliom index 6788d5dc..95ecd1c3 100644 --- a/template.distillery/demo_i18n.eliom +++ b/template.distillery/demo_i18n.eliom @@ -4,20 +4,6 @@ (* Ocsigen_i18n demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-i18n"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.internationalization ~capitalize:true] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-i18n" - (* Page for this demo *) let%shared page () = (* Syntax [%i18n key] or [%i18n Module.key] inserts @@ -43,3 +29,13 @@ let%shared page () = Demo.internationalization_4 ~f:[code [txt "assets/%%%PROJECT_NAME%%%_Demo_i18n.tsv"]] ~demo_prefix:[code [txt "demo_"]]] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_i18n + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-i18n"]] myid_o p ) diff --git a/template.distillery/demo_links.eliom b/template.distillery/demo_links.eliom index 4e9a3e9f..66eb07c9 100644 --- a/template.distillery/demo_links.eliom +++ b/template.distillery/demo_links.eliom @@ -4,20 +4,6 @@ (* Static files demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-static-files"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.links_and_static_files] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-links" - (* An example of external service: *) let%server ocsigen_service = Eliom_service.extern ~prefix:"http://ocsigen.org" ~path:[] @@ -70,3 +56,13 @@ let%shared page () = ~service:(Eliom_service.static_dir ()) ["images"; "ocsigen.png"]) () ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_links + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-links"]] myid_o p ) diff --git a/template.distillery/demo_notif.eliom b/template.distillery/demo_notif.eliom index 1dc12416..80f82f58 100644 --- a/template.distillery/demo_notif.eliom +++ b/template.distillery/demo_notif.eliom @@ -4,19 +4,8 @@ (* Notification demo *) open Js_of_ocaml_lwt] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-notif"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.notification] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-notif" +[%%shared open Eliom_content] +[%%shared open Html.D] (* Instantiate function Os_notif.Simple for each kind of notification you need. @@ -105,3 +94,13 @@ let%shared page () = ; txt [%i18n Demo.S.fill_input_form_send_message] ]) ; make_form [%i18n Demo.S.send_message] [%client (notify : string -> unit Lwt.t)] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_notif + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-notif"]] myid_o p ) diff --git a/template.distillery/demo_pagetransition.eliom b/template.distillery/demo_pagetransition.eliom index 2910cc33..a97c0504 100644 --- a/template.distillery/demo_pagetransition.eliom +++ b/template.distillery/demo_pagetransition.eliom @@ -13,28 +13,6 @@ open Eliom_content] [%%shared open Html.D] [%%client open Js_of_ocaml_lwt] -(* Service for this demo *) -let%server service = - Eliom_service.create - ~path:(Eliom_service.Path ["demo-page-transition"; ""]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -let%server detail_page_service = - Eliom_service.create - ~path:(Eliom_service.Path ["demo-page-transition"; "detail"; ""]) - ~meth:(Eliom_service.Get (Eliom_parameter.int "page")) - () - -(* Make service available on the client *) -let%client service = ~%service -let%client detail_page_service = ~%detail_page_service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.pagetransition] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-transition" - let%shared create_item index = let open F in li @@ -42,7 +20,9 @@ let%shared create_item index = [ a_class ["demo-list-item"; Printf.sprintf "demo-list-item-%d" (index mod 5)] ] - [a ~service:detail_page_service [txt (Printf.sprintf "list%d" index)] index] + [ a ~service:Demo_services.detail_page + [txt (Printf.sprintf "list%d" index)] + index ] let%shared page () = let l = @@ -93,3 +73,24 @@ let%shared make_detail_page page () = ([%i18n Demo.pagetransition_detail_page] @ [txt (Printf.sprintf " %d" page)]) ; back_button ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_pagetransition + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page + ~a:[a_class ["os-page-demo-pagetransition"]] + myid_o p ) + +let%shared () = + let detail_page_handler myid_o page () = + %%%MODULE_NAME%%%_container.page + ~a:[a_class ["os-page-demo-transition"]] + myid_o (make_detail_page page ()) + in + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.detail_page + (%%%MODULE_NAME%%%_page.Opt.connected_page detail_page_handler) diff --git a/template.distillery/demo_pgocaml.eliom b/template.distillery/demo_pgocaml.eliom index 6a20c2a8..393f3262 100644 --- a/template.distillery/demo_pgocaml.eliom +++ b/template.distillery/demo_pgocaml.eliom @@ -4,20 +4,6 @@ (* PGOcaml demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-pgocaml"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.pgocaml] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-pgocaml" - (* Fetch users in database *) let%rpc get_users () : string list Lwt.t = (* For this demo, we add a delay to simulate a network or db latency: *) @@ -44,3 +30,13 @@ let%shared page () = ; p [%i18n Demo.pgocaml_description_2] ; p [%i18n Demo.pgocaml_description_3] ; user_block ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_pgocaml + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-pgocaml"]] myid_o p ) diff --git a/template.distillery/demo_popup.eliom b/template.distillery/demo_popup.eliom index 910bb937..e5ec15e3 100644 --- a/template.distillery/demo_popup.eliom +++ b/template.distillery/demo_popup.eliom @@ -7,20 +7,9 @@ open Eliom_content.Html] [%%shared open Eliom_content.Html.F] [%%client open Js_of_ocaml_lwt] -(* Service for this demo, defined in the server-side app *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-popup"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - (* Name for demo menu. This value is defined both server and client-side. *) let%shared name () = [%i18n Demo.S.popup] -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-popup" - (* The function generating the page can be called either from the server or the client (shared section). *) let%shared page () = @@ -67,3 +56,13 @@ let%shared page () = See internationalization demo for i18n syntax. *) Lwt.return [h1 [%i18n Demo.popup]; p [%i18n Demo.popup_content]; p [button]] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_popup + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-popup"]] myid_o p ) diff --git a/template.distillery/demo_pulltorefresh.eliom b/template.distillery/demo_pulltorefresh.eliom index 59fd3b94..75d04ec5 100644 --- a/template.distillery/demo_pulltorefresh.eliom +++ b/template.distillery/demo_pulltorefresh.eliom @@ -4,20 +4,7 @@ (** Demo for refreshable content *) [%%shared open Eliom_content.Html] - -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-pull-to-refresh"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.pull_to_refresh] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-pull" +[%%shared open Eliom_content.Html.D] let%shared page () = let counter_sig, set_counter = Eliom_shared.React.S.create 0 in @@ -46,3 +33,14 @@ let%shared page () = ; R.node counter_node_sig ] in Lwt.return @@ [Ot_pulltorefresh.make ~dragThreshold:15. ~content reload] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_pulltorefresh + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-pulltorefresh"]] myid_o p + ) diff --git a/template.distillery/demo_react.eliom b/template.distillery/demo_react.eliom index a61f3914..2be82041 100644 --- a/template.distillery/demo_react.eliom +++ b/template.distillery/demo_react.eliom @@ -4,20 +4,8 @@ (** Demo for shared reactive content *) [%%client open Js_of_ocaml_lwt] - -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-react"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.reactive_programming] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-react" +[%%shared open Eliom_content] +[%%shared open Html.D] (* Make a text input field that calls [f s] for each [s] submitted *) let%shared make_form msg f = @@ -71,3 +59,13 @@ let%shared page () = ; F.p [F.txt [%i18n Demo.S.reactive_programming_3]] ; inp ; F.div [R.ul l] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_react + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-react"]] myid_o p ) diff --git a/template.distillery/demo_ref.eliom b/template.distillery/demo_ref.eliom index 7d021967..3ef18367 100644 --- a/template.distillery/demo_ref.eliom +++ b/template.distillery/demo_ref.eliom @@ -4,20 +4,6 @@ (* Demo for Eliom references and Os_date *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-ref"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.eliom_ref] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-ref" - (* An Eliom reference storing the last time the user visited the current page. It has scope Eliom_common.default_group_scope, which means that the value will be different for each user of the Web site, but the same @@ -53,3 +39,13 @@ let%shared page () = ; p [txt [%i18n Demo.S.eliom_ref_2]] ; p last_visit_message ; p [txt [%i18n Demo.S.eliom_ref_3]] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_ref + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-ref"]] myid_o p ) diff --git a/template.distillery/demo_rpc.eliom b/template.distillery/demo_rpc.eliom index 0bf9fac1..781e8692 100644 --- a/template.distillery/demo_rpc.eliom +++ b/template.distillery/demo_rpc.eliom @@ -4,19 +4,8 @@ (* RPC button demo *) open Js_of_ocaml_lwt] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-rpc"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.rpc_button] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-rpc" +[%%shared open Eliom_content] +[%%shared open Html.D] (* A server-side reference that stores data for the current browser (scope = session). @@ -61,3 +50,13 @@ let%shared page () = [ F.h1 [%i18n Demo.rpc_button] ; F.p [F.txt [%i18n Demo.S.rpc_button_description]] ; F.p [btn] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_rpc + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-rpc"]] myid_o p ) diff --git a/template.distillery/demo_services.eliom b/template.distillery/demo_services.eliom new file mode 100644 index 00000000..9f1826aa --- /dev/null +++ b/template.distillery/demo_services.eliom @@ -0,0 +1,145 @@ +(* Services for each demo page *) + +(* Services are defined in this module for dependency reasons: + Each page contains a menu, with links towards each service. +*) + +(* Services are first defined in the server-side app, + then the client-side value is defined as injections. + Services cannot usually be created in shared sections + as some random identifiers must be the same on both sides. +*) + +let%server demo = + Eliom_service.create ~path:(Eliom_service.Path ["demo"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo = ~%demo + +let%server demo_popup = + Eliom_service.create ~path:(Eliom_service.Path ["demo-popup"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_popup = ~%demo_popup + +let%server demo_rpc = + Eliom_service.create ~path:(Eliom_service.Path ["demo-rpc"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_rpc = ~%demo_rpc + +let%server demo_ref = + Eliom_service.create ~path:(Eliom_service.Path ["demo-ref"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_ref = ~%demo_ref + +let%server demo_spinner = + Eliom_service.create ~path:(Eliom_service.Path ["demo-spinner"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_spinner = ~%demo_spinner + +let%server demo_pgocaml = + Eliom_service.create ~path:(Eliom_service.Path ["demo-pgocaml"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_pgocaml = ~%demo_pgocaml + +let%server demo_users = + Eliom_service.create ~path:(Eliom_service.Path ["demo-users"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_users = ~%demo_users + +let%server demo_links = + Eliom_service.create ~path:(Eliom_service.Path ["demo-links"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_links = ~%demo_links + +let%server demo_i18n = + Eliom_service.create ~path:(Eliom_service.Path ["demo-i18n"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_i18n = ~%demo_i18n + +let%server demo_tips = + Eliom_service.create ~path:(Eliom_service.Path ["demo-tips"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_tips = ~%demo_tips + +let%server demo_carousel1 = + Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel1"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_carousel1 = ~%demo_carousel1 + +let%server demo_carousel2 = + Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel2"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_carousel2 = ~%demo_carousel2 + +let%server demo_carousel3 = + Eliom_service.create ~path:(Eliom_service.Path ["demo-carousel3"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_carousel3 = ~%demo_carousel3 + +let%server demo_tongue = + Eliom_service.create ~path:(Eliom_service.Path ["demo-tongue"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_tongue = ~%demo_tongue + +let%server demo_calendar = + Eliom_service.create ~path:(Eliom_service.Path ["demo-calendar"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_calendar = ~%demo_calendar + +let%server demo_timepicker = + Eliom_service.create ~path:(Eliom_service.Path ["demo-timepicker"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_timepicker = ~%demo_timepicker + +let%server demo_notif = + Eliom_service.create ~path:(Eliom_service.Path ["demo-notif"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_notif = ~%demo_notif + +let%server demo_react = + Eliom_service.create ~path:(Eliom_service.Path ["demo-react"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_react = ~%demo_react + +let%server demo_pulltorefresh = + Eliom_service.create ~path:(Eliom_service.Path ["demo-pulltorefresh"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_pulltorefresh = ~%demo_pulltorefresh + +let%server demo_cache = + Eliom_service.create ~path:(Eliom_service.Path ["demo-cache"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_cache = ~%demo_cache + +let%server demo_pagetransition = + Eliom_service.create ~path:(Eliom_service.Path ["demo-pagetransition"]) + ~meth:(Eliom_service.Get Eliom_parameter.unit) () + +let%client demo_pagetransition = ~%demo_pagetransition + +let%server detail_page = + Eliom_service.create + ~path:(Eliom_service.Path ["demo-page-transition"; "detail"; ""]) + ~meth:(Eliom_service.Get (Eliom_parameter.int "page")) + () + +let%client detail_page = ~%detail_page diff --git a/template.distillery/demo_spinner.eliom b/template.distillery/demo_spinner.eliom index 7b3c5bda..57b69088 100644 --- a/template.distillery/demo_spinner.eliom +++ b/template.distillery/demo_spinner.eliom @@ -4,19 +4,8 @@ (* Spinner demo *) open Js_of_ocaml_lwt] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-spinner"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.spinner] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-spinner" +[%%shared open Eliom_content] +[%%shared open Html.D] (* Build the spinner *) let%client make_spinner () = @@ -42,3 +31,13 @@ let%shared page () : Html_types.div_content Eliom_content.Html.elt list Lwt.t = ; F.p [F.txt [%i18n Demo.S.spinner_description_3]] ; F.p [F.txt [%i18n Demo.S.spinner_generated_client_side]] ; C.node [%client (make_spinner () : [> `Div] Eliom_content.Html.elt)] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_spinner + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-spinner"]] myid_o p ) diff --git a/template.distillery/demo_timepicker.eliom b/template.distillery/demo_timepicker.eliom index 259b1194..6e081dc7 100644 --- a/template.distillery/demo_timepicker.eliom +++ b/template.distillery/demo_timepicker.eliom @@ -7,13 +7,6 @@ open Eliom_content.Html.D] (* Timepicker demo *) -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-timepicker"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service let%server s, f = Eliom_shared.React.S.create None let%client action (h, m) = @@ -31,12 +24,6 @@ let%server time_as_string () : string Eliom_shared.React.S.t = let%rpc time_reactive () : string Eliom_shared.React.S.t Lwt.t = Lwt.return @@ time_as_string () -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.timepicker] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-timepicker" - (* Page for this demo *) let%shared page () = let time_picker, _, back_f = @@ -58,3 +45,13 @@ let%shared page () = ; div [time_picker] ; p [Eliom_content.Html.R.txt tr] ; div [button] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_timepicker + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-timepicker"]] myid_o p ) diff --git a/template.distillery/demo_tips.eliom b/template.distillery/demo_tips.eliom index c688add6..862d7853 100644 --- a/template.distillery/demo_tips.eliom +++ b/template.distillery/demo_tips.eliom @@ -4,20 +4,6 @@ (* Os_tips demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-tips"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.tips] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-tips" - (* Here is an example of tip. Call this function while generating the widget concerned by the explanation it contains. *) let%shared example_tip () = @@ -44,5 +30,15 @@ let%shared page () = [%i18n Demo.tips4 ~set_page: - [ a ~service:%%%MODULE_NAME%%%_services.settings_service [%i18n Demo.tips5] - () ]] ] + [a ~service:%%%MODULE_NAME%%%_services.settings_service [%i18n Demo.tips5] ()]] + ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_tips + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-tips"]] myid_o p ) diff --git a/template.distillery/demo_tongue.eliom b/template.distillery/demo_tongue.eliom index 869adfee..3181dc6a 100644 --- a/template.distillery/demo_tongue.eliom +++ b/template.distillery/demo_tongue.eliom @@ -4,20 +4,6 @@ (* Tongue demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-tongue"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.tongue_1] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-tongue" - (* Page for this demo *) let%shared page () = let content = @@ -37,3 +23,13 @@ let%shared page () = [ h1 [%i18n Demo.tongue_1] ; p [%i18n Demo.ot_tongue_1] ; div ~a:[a_class ["demo-tongue"]] [tongue.Ot_tongue.elt] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_tongue + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-tongue"]] myid_o p ) diff --git a/template.distillery/demo_tools.eliom b/template.distillery/demo_tools.eliom index 585dc9b0..db81dc32 100644 --- a/template.distillery/demo_tools.eliom +++ b/template.distillery/demo_tools.eliom @@ -3,59 +3,37 @@ [%%shared.start] -module type Page = sig - val name : unit -> string - val page_class : string - - val service : - ( unit - , unit - , Eliom_service.get - , Eliom_service.att - , Eliom_service.non_co - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , unit - , Eliom_service.non_ocaml ) - Eliom_service.t - - val page : unit -> Html_types.div_content Eliom_content.Html.D.elt list Lwt.t -end - let demos = - [ (module Demo_popup : Page) - ; (module Demo_rpc) - ; (module Demo_ref) - ; (module Demo_spinner) - ; (module Demo_pgocaml) - ; (module Demo_users) - ; (module Demo_links) - ; (module Demo_i18n) - ; (module Demo_tips) - ; (module Demo_carousel1) - ; (module Demo_carousel2) - ; (module Demo_carousel3) - ; (module Demo_tongue) - ; (module Demo_calendar) - ; (module Demo_timepicker) - ; (module Demo_notif) - ; (module Demo_react) - ; (module Demo_pulltorefresh) - ; (module Demo_cache) - ; (module Demo_pagetransition) ] + [ (fun () -> [%i18n Demo.S.rpc_button]), Demo_services.demo_rpc + ; (fun () -> [%i18n Demo.S.eliom_ref]), Demo_services.demo_ref + ; (fun () -> [%i18n Demo.S.spinner]), Demo_services.demo_spinner + ; (fun () -> [%i18n Demo.S.pgocaml]), Demo_services.demo_pgocaml + ; (fun () -> [%i18n Demo.S.users]), Demo_services.demo_users + ; (fun () -> [%i18n Demo.S.links_and_static_files]), Demo_services.demo_links + ; ( (fun () -> [%i18n Demo.S.internationalization ~capitalize:true]) + , Demo_services.demo_i18n ) + ; (fun () -> [%i18n Demo.S.tips]), Demo_services.demo_tips + ; (fun () -> [%i18n Demo.S.carousel_1]), Demo_services.demo_carousel1 + ; (fun () -> [%i18n Demo.S.carousel_2]), Demo_services.demo_carousel2 + ; (fun () -> [%i18n Demo.S.carousel_wheel]), Demo_services.demo_carousel3 + ; (fun () -> [%i18n Demo.S.tongue_1]), Demo_services.demo_tongue + ; (fun () -> [%i18n Demo.S.calendar]), Demo_services.demo_calendar + ; (fun () -> [%i18n Demo.S.timepicker]), Demo_services.demo_timepicker + ; (fun () -> [%i18n Demo.S.notification]), Demo_services.demo_notif + ; (fun () -> [%i18n Demo.S.reactive_programming]), Demo_services.demo_react + ; (fun () -> [%i18n Demo.S.pull_to_refresh]), Demo_services.demo_pulltorefresh + ; (fun () -> [%i18n Demo.S.cache]), Demo_services.demo_cache + ; (fun () -> [%i18n Demo.S.pagetransition]), Demo_services.demo_pagetransition + ] let drawer_contents () = let open Eliom_content.Html.F in - let make_link (module D : Page) = - li [a ~service:D.service [txt @@ D.name ()] ()] - in + let make_link (name, service) = li [a ~service [txt @@ name ()] ()] in let submenu = ul ~a:[a_class ["os-drawer-submenu"]] (List.map make_link demos) in li [ a ~a:[a_class ["os-drawer-item"]] - ~service:%%%MODULE_NAME%%%_services.demo_service [%i18n Demo.intro] () + ~service:Demo_services.demo [%i18n Demo.intro] () ; submenu ] diff --git a/template.distillery/demo_users.eliom b/template.distillery/demo_users.eliom index 85ab3f36..8a19c0d8 100644 --- a/template.distillery/demo_users.eliom +++ b/template.distillery/demo_users.eliom @@ -4,20 +4,6 @@ (* Os_current_user demo *) open Eliom_content.Html.F] -(* Service for this demo *) -let%server service = - Eliom_service.create ~path:(Eliom_service.Path ["demo-users"]) - ~meth:(Eliom_service.Get Eliom_parameter.unit) () - -(* Make service available on the client *) -let%client service = ~%service - -(* Name for demo menu *) -let%shared name () = [%i18n Demo.S.users] - -(* Class for the page containing this demo (for internal use) *) -let%shared page_class = "os-page-demo-users" - let%shared display_user_name = function | None -> p [%i18n Demo.you_are_not_connected] | Some user -> @@ -55,3 +41,13 @@ let%shared page () = [ txt [%i18n Demo.S.always_get_current_user_using_module] ; code [txt " Os_current_user. "] ; txt [%i18n Demo.S.never_trust_client_pending_user_id] ] ] + +(* Service registration is done on both sides (shared section), + so that pages can be generated from the server + (first request, crawling, search engines ...) + or the client (subsequent link clicks, or mobile app ...). *) +let%shared () = + %%%MODULE_NAME%%%_base.App.register ~service:Demo_services.demo_users + ( %%%MODULE_NAME%%%_page.Opt.connected_page @@ fun myid_o () () -> + let%lwt p = page () in + %%%MODULE_NAME%%%_container.page ~a:[a_class ["os-page-demo-users"]] myid_o p )