diff --git a/opam b/opam index 7db39ca4..ff6f521c 100644 --- a/opam +++ b/opam @@ -1,6 +1,6 @@ opam-version: "2.0" name: "ocsigen-start" -version: "6.1.2" +version: "6.2.0" authors: "dev@ocsigen.org" maintainer: "dev@ocsigen.org" synopsis: "Higher-level library for developing Web and mobile applications with users, registration, notifications, etc" diff --git a/template.distillery/PROJECT_NAME.eliom b/template.distillery/PROJECT_NAME.eliom index 197f45dd..56ab16a8 100644 --- a/template.distillery/PROJECT_NAME.eliom +++ b/template.distillery/PROJECT_NAME.eliom @@ -30,28 +30,22 @@ let%shared () = (Os_session.Opt.connected_fun %%%MODULE_NAME%%%_handlers.action_link_handler); Eliom_registration.Action.register ~service:Os_services.add_email_service (fun () email -> - let%lwt () = Os_handlers.add_email_handler () email in - add_email_notif (); Lwt.return_unit); + let%lwt () = Os_handlers.add_email_handler () email in + add_email_notif (); Lwt.return_unit); Eliom_registration.Action.register ~service:Os_services.update_language_service %%%MODULE_NAME%%%_handlers.update_language_handler; %%%MODULE_NAME%%%_base.App.register ~service:Os_services.main_service - (%%%MODULE_NAME%%%_page.Opt.connected_page - %%%MODULE_NAME%%%_handlers.main_service_handler); - %%%MODULE_NAME%%%_base.App.register - ~service:%%%MODULE_NAME%%%_services.about_service - (%%%MODULE_NAME%%%_page.Opt.connected_page - %%%MODULE_NAME%%%_handlers.about_handler); - %%%MODULE_NAME%%%_base.App.register - ~service:%%%MODULE_NAME%%%_services.settings_service - (%%%MODULE_NAME%%%_page.Opt.connected_page - %%%MODULE_NAME%%%_handlers.settings_handler) + (%%%MODULE_NAME%%%_page.Opt.connected_page %%%MODULE_NAME%%%_handlers.main_service_handler); + %%%MODULE_NAME%%%_base.App.register ~service:%%%MODULE_NAME%%%_services.about_service + (%%%MODULE_NAME%%%_page.Opt.connected_page %%%MODULE_NAME%%%_handlers.about_handler); + %%%MODULE_NAME%%%_base.App.register ~service:%%%MODULE_NAME%%%_services.settings_service + (%%%MODULE_NAME%%%_page.Opt.connected_page %%%MODULE_NAME%%%_handlers.settings_handler) let%server () = Eliom_registration.Ocaml.register ~service:%%%MODULE_NAME%%%_services.upload_user_avatar_service - (Os_session.connected_fun - %%%MODULE_NAME%%%_handlers.upload_user_avatar_handler) + (Os_session.connected_fun %%%MODULE_NAME%%%_handlers.upload_user_avatar_handler) (* Print more debugging information when is in config file (DEBUG = yes in Makefile.options). @@ -60,7 +54,7 @@ let%server () = ... Lwt_log.ign_info ~section "This is an information"; (or ign_debug, ign_warning, ign_error etc.) - *) +*) let%server _ = if Eliom_config.get_debugmode () then ( @@ -71,14 +65,14 @@ let%server _ = (* Lwt_log_core.add_rule "os*" Lwt_log_js.Debug; *) Lwt_log_core.add_rule "%%%MODULE_NAME%%%*" Lwt_log_js.Debug (* Lwt_log_core.add_rule "*" Lwt_log_js.Debug *) - : unit)]; + : unit)]; (* Lwt_log_core.add_rule "*" Lwt_log.Debug *) Lwt_log_core.add_rule "%%%MODULE_NAME%%%*" Lwt_log.Debug) (* 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 @@ -104,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_base.eliom b/template.distillery/PROJECT_NAME_base.eliom index 6603c039..60d28cfc 100644 --- a/template.distillery/PROJECT_NAME_base.eliom +++ b/template.distillery/PROJECT_NAME_base.eliom @@ -7,29 +7,24 @@ let%shared displayed_app_name = "%%%PROJECT_NAME%%%" (* Database initialization *) let () = - Os_db.init - ?host:!%%%MODULE_NAME%%%_config.os_db_host - ?port:!%%%MODULE_NAME%%%_config.os_db_port + Os_db.init ?host:!%%%MODULE_NAME%%%_config.os_db_host ?port:!%%%MODULE_NAME%%%_config.os_db_port ?user:!%%%MODULE_NAME%%%_config.os_db_user ?password:!%%%MODULE_NAME%%%_config.os_db_password ?database:!%%%MODULE_NAME%%%_config.os_db_database - ?unix_domain_socket_dir: - !%%%MODULE_NAME%%%_config.os_db_unix_domain_socket_dir + ?unix_domain_socket_dir:!%%%MODULE_NAME%%%_config.os_db_unix_domain_socket_dir () let () = Os_email.set_mailer "/usr/sbin/sendmail" - -let () = - Os_email.set_from_addr ("%%%PROJECT_NAME%%% team", "noreply@DEFAULT.DEFAULT") +let () = Os_email.set_from_addr ("%%%PROJECT_NAME%%% team", "noreply@DEFAULT.DEFAULT") (* Create a module for the application. See https://ocsigen.org/eliom/manual/clientserver-applications for more information. *) [%%shared module App = Eliom_registration.App (struct - let application_name = application_name - let global_data_path = Some ["__global_data__"] -end)] + let application_name = application_name + let global_data_path = Some ["__global_data__"] + end)] (* As the headers (stylesheets, etc) won't change, we ask Eliom not to update the of the page when changing page. (This also avoids diff --git a/template.distillery/PROJECT_NAME_config.eliom b/template.distillery/PROJECT_NAME_config.eliom index d97e604f..b958b3c6 100644 --- a/template.distillery/PROJECT_NAME_config.eliom +++ b/template.distillery/PROJECT_NAME_config.eliom @@ -47,7 +47,7 @@ let avatars = let open Ocsigen_extensions.Configuration in let attributes = [ attribute ~name:"dir" ~obligatory:true (fun h -> - avatar_dir := Eliom_lib.String.split '/' h) ] + avatar_dir := Eliom_lib.String.split '/' h) ] in element ~name:"avatars" ~obligatory:true ~attributes () @@ -57,17 +57,16 @@ let os_db = let attributes = [ attribute ~name:"host" (fun h -> os_db_host := Some h) ; attribute ~name:"port" (fun h -> - os_db_port := - try Some (int_of_string h) - with Failure _ -> - raise - @@ Ocsigen_extensions.Error_in_config_file - "port is not an integer") + os_db_port := + try Some (int_of_string h) + with Failure _ -> + raise + @@ Ocsigen_extensions.Error_in_config_file "port is not an integer") ; attribute ~name:"user" (fun h -> os_db_user := Some h) ; attribute ~name:"password" (fun h -> os_db_password := Some h) ; attribute ~name:"database" (fun h -> os_db_database := Some h) ; attribute ~name:"unix_domain_socket_dir" (fun h -> - os_db_unix_domain_socket_dir := Some h) ] + os_db_unix_domain_socket_dir := Some h) ] in element ~name:"os-db" ~attributes () diff --git a/template.distillery/PROJECT_NAME_container.eliom b/template.distillery/PROJECT_NAME_container.eliom index 946fe8cc..4fe0b2db 100644 --- a/template.distillery/PROJECT_NAME_container.eliom +++ b/template.distillery/PROJECT_NAME_container.eliom @@ -30,14 +30,14 @@ let%shared os_footer () = [ p [ txt [%i18n S.footer_generated] ; a ~service:%%%MODULE_NAME%%%_services.os_github_service - [txt " Ocsigen Start "] () + [txt " Ocsigen Start "] + () ; txt [%i18n S.footer_eliom_distillery] - ; a ~service:%%%MODULE_NAME%%%_services.ocsigen_service - [txt " Ocsigen "] () + ; a ~service:%%%MODULE_NAME%%%_services.ocsigen_service [txt " Ocsigen "] () ; txt [%i18n S.footer_technology] ] ] -let%rpc get_wrong_pdata () - : ((string * string) * (string * string)) option Lwt.t +let%rpc get_wrong_pdata () : + ((string * string) * (string * string)) option Lwt.t = Lwt.return @@ Eliom_reference.Volatile.get Os_msg.wrong_pdata diff --git a/template.distillery/PROJECT_NAME_drawer.eliom b/template.distillery/PROJECT_NAME_drawer.eliom index 7cc2b504..9a9853e6 100644 --- a/template.distillery/PROJECT_NAME_drawer.eliom +++ b/template.distillery/PROJECT_NAME_drawer.eliom @@ -9,9 +9,7 @@ let%shared item text service = li [a ~a:[a_class ["os-drawer-item"]] ~service [txt text] ()] let%shared user_menu () = - [ item - [%i18n S.settings ~capitalize:true] - %%%MODULE_NAME%%%_services.settings_service + [ item [%i18n S.settings ~capitalize:true] %%%MODULE_NAME%%%_services.settings_service ; Eliom_content.Html.F.li [ Os_user_view.disconnect_link ~text_logout:[%i18n S.logout ~capitalize:true] @@ -22,8 +20,7 @@ let%shared make ?user () = let items = if user = None then [] else user_menu () in let items = item [%i18n S.home ~capitalize:true] Os_services.main_service - :: item [%i18n S.about ~capitalize:true] - %%%MODULE_NAME%%%_services.about_service + :: item [%i18n S.about ~capitalize:true] %%%MODULE_NAME%%%_services.about_service :: Demo_tools.drawer_contents () :: items in diff --git a/template.distillery/PROJECT_NAME_handlers.eliom b/template.distillery/PROJECT_NAME_handlers.eliom index feefe491..6171126d 100644 --- a/template.distillery/PROJECT_NAME_handlers.eliom +++ b/template.distillery/PROJECT_NAME_handlers.eliom @@ -25,8 +25,8 @@ let upload_user_avatar_handler myid () ((), (cropping, photo)) = let%server set_personal_data_handler = Os_session.connected_fun Os_handlers.set_personal_data_handler -let%rpc set_personal_data_rpc (data : (string * string) * (string * string)) - : unit Lwt.t +let%rpc set_personal_data_rpc (data : (string * string) * (string * string)) : + unit Lwt.t = set_personal_data_handler () data @@ -35,8 +35,7 @@ let%client set_personal_data_handler () = set_personal_data_rpc (* Forgot password *) let%server forgot_password_handler = - Os_handlers.forgot_password_handler - %%%MODULE_NAME%%%_services.settings_service + Os_handlers.forgot_password_handler %%%MODULE_NAME%%%_services.settings_service let%rpc forgot_password_rpc (email : string) : unit Lwt.t = forgot_password_handler () email @@ -96,8 +95,7 @@ let%shared action_link_handler myid_o akey () = ~a_placeholder_email:[%i18n S.your_email] ~text:[%i18n S.sign_up] ~email () ] ] in - %%%MODULE_NAME%%%_base.App.send - (%%%MODULE_NAME%%%_page.make_page (Os_page.content page)) + %%%MODULE_NAME%%%_base.App.send (%%%MODULE_NAME%%%_page.make_page (Os_page.content page)) else let page = [ div @@ -108,8 +106,7 @@ let%shared action_link_handler myid_o akey () = ~text_keep_me_logged_in:[%i18n S.keep_logged_in] ~text_sign_in:[%i18n S.sign_in] ~email () ] ] in - %%%MODULE_NAME%%%_base.App.send - (%%%MODULE_NAME%%%_page.make_page (Os_page.content page)) + %%%MODULE_NAME%%%_base.App.send (%%%MODULE_NAME%%%_page.make_page (Os_page.content page)) else (*VVV In that case we must do something more complex. Check whether myid = userid and ask the user what he wants to @@ -122,8 +119,8 @@ let%shared action_link_handler myid_o akey () = let%server set_password_handler = Os_session.connected_fun (fun myid () (pwd, pwd2) -> - let%lwt () = Os_handlers.set_password_handler myid () (pwd, pwd2) in - Lwt.return (Eliom_registration.Redirection Eliom_service.reload_action)) + let%lwt () = Os_handlers.set_password_handler myid () (pwd, pwd2) in + Lwt.return (Eliom_registration.Redirection Eliom_service.reload_action)) let%client set_password_handler () (pwd, pwd2) = let%lwt () = Os_handlers.set_password_rpc (pwd, pwd2) in diff --git a/template.distillery/PROJECT_NAME_language.eliom b/template.distillery/PROJECT_NAME_language.eliom index 195dd2b8..dc32fb9f 100644 --- a/template.distillery/PROJECT_NAME_language.eliom +++ b/template.distillery/PROJECT_NAME_language.eliom @@ -35,24 +35,22 @@ let%server update_language lang = let%server _ = Os_session.on_start_process (fun _ -> - (* Guess a default language. *) - let%lwt lang = best_matched_language () in - ignore (update_language lang); - Lwt.return_unit); + (* Guess a default language. *) + let%lwt lang = best_matched_language () in + ignore (update_language lang); + Lwt.return_unit); Os_session.on_start_connected_process (fun userid -> - (* Set language according to user preferences. *) - let%lwt language = - match%lwt Os_user.get_language userid with - | Some lang -> - Lwt.return (%%%MODULE_NAME%%%_i18n.guess_language_of_string lang) - | None -> - let%lwt best_language = best_matched_language () in - ignore - (Os_user.update_language ~userid - ~language: - (%%%MODULE_NAME%%%_i18n.string_of_language best_language)); - Lwt.return best_language - in - %%%MODULE_NAME%%%_i18n.set_language language; - ignore [%client (%%%MODULE_NAME%%%_i18n.set_language ~%language : unit)]; - Lwt.return_unit) + (* Set language according to user preferences. *) + let%lwt language = + match%lwt Os_user.get_language userid with + | Some lang -> Lwt.return (%%%MODULE_NAME%%%_i18n.guess_language_of_string lang) + | None -> + let%lwt best_language = best_matched_language () in + ignore + (Os_user.update_language ~userid + ~language:(%%%MODULE_NAME%%%_i18n.string_of_language best_language)); + Lwt.return best_language + in + %%%MODULE_NAME%%%_i18n.set_language language; + ignore [%client (%%%MODULE_NAME%%%_i18n.set_language ~%language : unit)]; + Lwt.return_unit) diff --git a/template.distillery/PROJECT_NAME_mobile.eliom b/template.distillery/PROJECT_NAME_mobile.eliom index f923b006..ca2161f3 100644 --- a/template.distillery/PROJECT_NAME_mobile.eliom +++ b/template.distillery/PROJECT_NAME_mobile.eliom @@ -30,12 +30,11 @@ let to_lwt f = let ondeviceready = to_lwt (fun cont -> - ignore - @@ Js_of_ocaml.Dom.addEventListener Js_of_ocaml.Dom_html.document - (Js_of_ocaml.Dom_html.Event.make "deviceready") - (Js_of_ocaml.Dom_html.handler (fun _ -> - cont (); Js_of_ocaml.Js._true)) - Js_of_ocaml.Js._false) + ignore + @@ Js_of_ocaml.Dom.addEventListener Js_of_ocaml.Dom_html.document + (Js_of_ocaml.Dom_html.Event.make "deviceready") + (Js_of_ocaml.Dom_html.handler (fun _ -> cont (); Js_of_ocaml.Js._true)) + Js_of_ocaml.Js._false) let app_started = ref false let initial_change_page = ref None @@ -80,9 +79,9 @@ let () = @@ Js_of_ocaml.Dom.addEventListener Js_of_ocaml.Dom_html.document (Js_of_ocaml.Dom_html.Event.make ev) (Js_of_ocaml.Dom_html.handler (fun _ -> - Firebug.console##log (Js_of_ocaml.Js.string ev); - Eliom_comet.activate (); - Js_of_ocaml.Js._true)) + Firebug.console##log (Js_of_ocaml.Js.string ev); + Eliom_comet.activate (); + Js_of_ocaml.Js._true)) Js_of_ocaml.Js._false in activate "online"; activate "resume" @@ -102,8 +101,8 @@ let () = (st##getItem lc) (fun () -> ()) (fun url -> - st##removeItem lc; - change_page_uri (Js_of_ocaml.Js.to_string url)) + st##removeItem lc; + change_page_uri (Js_of_ocaml.Js.to_string url)) (* Handle universal links *) @@ -121,15 +120,15 @@ let universal_links () = let%lwt () = ondeviceready in Lwt.return @@ Js_of_ocaml.Js.Optdef.to_option @@ (Js_of_ocaml.Js.Unsafe.global##.universalLinks - : < subscribe : - Js_of_ocaml.Js.js_string Js_of_ocaml.Js.opt - -> (event Js_of_ocaml.Js.t -> unit) Js_of_ocaml.Js.callback - -> unit Js_of_ocaml.Js.meth - ; unsubscribe : - Js_of_ocaml.Js.js_string Js_of_ocaml.Js.opt - -> unit Js_of_ocaml.Js.meth > - Js_of_ocaml.Js.t - Js_of_ocaml.Js.Optdef.t) + : < subscribe : + Js_of_ocaml.Js.js_string Js_of_ocaml.Js.opt + -> (event Js_of_ocaml.Js.t -> unit) Js_of_ocaml.Js.callback + -> unit Js_of_ocaml.Js.meth + ; unsubscribe : + Js_of_ocaml.Js.js_string Js_of_ocaml.Js.opt + -> unit Js_of_ocaml.Js.meth > + Js_of_ocaml.Js.t + Js_of_ocaml.Js.Optdef.t) let _ = match%lwt universal_links () with @@ -138,10 +137,10 @@ let _ = (Js_of_ocaml.Js.string "Universal links: registering"); universal_links##subscribe Js_of_ocaml.Js.null (Js_of_ocaml.Js.wrap_callback (fun (ev : event Js_of_ocaml.Js.t) -> - Js_of_ocaml.Firebug.console##log_2 - (Js_of_ocaml.Js.string "Universal links: got link") - ev##.url; - change_page_uri (Js_of_ocaml.Js.to_string ev##.url))); + Js_of_ocaml.Firebug.console##log_2 + (Js_of_ocaml.Js.string "Universal links: got link") + ev##.url; + change_page_uri (Js_of_ocaml.Js.to_string ev##.url))); Js_of_ocaml.Firebug.console##log (Js_of_ocaml.Js.string "Universal links: registered"); Lwt.return_unit diff --git a/template.distillery/PROJECT_NAME_page.eliom b/template.distillery/PROJECT_NAME_page.eliom index 9327b1e6..698f9da1 100644 --- a/template.distillery/PROJECT_NAME_page.eliom +++ b/template.distillery/PROJECT_NAME_page.eliom @@ -22,9 +22,7 @@ let%client css_name_script = [] (* Warning: either we use exactly the same global node (and make sure global nodes work properly on client side), or we do not add the script on client side. We chose the second solution. *) -let%server app_js = - [%%%MODULE_NAME%%%_base.App.application_script ~defer:true ()] - +let%server app_js = [%%%MODULE_NAME%%%_base.App.application_script ~defer:true ()] let%client app_js = [] let%server the_local_js = [] let%client the_local_js = [] (* in index.html *) @@ -53,14 +51,14 @@ module Page_config = struct let default_error_page _ _ exn = %%%MODULE_NAME%%%_container.page None (if Ocsigen_config.get_debugmode () - then [p [txt (Printexc.to_string exn)]] - else [p [txt "Error"]]) + then [p [txt (Printexc.to_string exn)]] + else [p [txt "Error"]]) let default_connected_error_page myid_o _ _ exn = %%%MODULE_NAME%%%_container.page myid_o (if Ocsigen_config.get_debugmode () - then [p [txt (Printexc.to_string exn)]] - else [p [txt "Error"]]) + then [p [txt (Printexc.to_string exn)]] + else [p [txt "Error"]]) end include Os_page.Make (Page_config)] diff --git a/template.distillery/PROJECT_NAME_phone_connect.eliom b/template.distillery/PROJECT_NAME_phone_connect.eliom index ea5da8c0..5859727e 100644 --- a/template.distillery/PROJECT_NAME_phone_connect.eliom +++ b/template.distillery/PROJECT_NAME_phone_connect.eliom @@ -18,8 +18,8 @@ let%server () = if enable then Os_connect_phone.set_send_sms_handler (fun ~number message -> - Printf.printf "Send SMS %s to %s\n%!" message number; - Lwt.return (Ok ())) + Printf.printf "Send SMS %s to %s\n%!" message number; + Lwt.return (Ok ())) let () = if enable diff --git a/template.distillery/PROJECT_NAME_services.eliom b/template.distillery/PROJECT_NAME_services.eliom index ac994013..c4c5fa2c 100644 --- a/template.distillery/PROJECT_NAME_services.eliom +++ b/template.distillery/PROJECT_NAME_services.eliom @@ -2,22 +2,15 @@ Feel free to use it, modify it, and redistribute it as you wish. *) let%server about_service = - Eliom_service.create - ~path:(Eliom_service.Path ["about"]) + Eliom_service.create ~path:(Eliom_service.Path ["about"]) ~meth:(Eliom_service.Get Eliom_parameter.unit) () 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"]) + Eliom_service.create ~path:(Eliom_service.Path ["settings"]) ~meth:(Eliom_service.Get Eliom_parameter.unit) () let%server os_github_service = @@ -31,10 +24,10 @@ let%server ocsigen_service = let%client about_service = ~%about_service let%client upload_user_avatar_service = ~%upload_user_avatar_service -let%client demo_service = ~%demo_service let%client settings_service = ~%settings_service let%client ocsigen_service = ~%ocsigen_service let%client os_github_service = ~%os_github_service + (* The OS lib needs access to the settings service to perform redirections to it. We need to register it *) let%server () = Os_services.register_settings_service settings_service diff --git a/template.distillery/PROJECT_NAME_services.eliomi b/template.distillery/PROJECT_NAME_services.eliomi index 931ee62e..cf286afa 100644 --- a/template.distillery/PROJECT_NAME_services.eliomi +++ b/template.distillery/PROJECT_NAME_services.eliomi @@ -19,20 +19,6 @@ val about_service : val upload_user_avatar_service : (unit, unit) Ot_picture_uploader.service -val demo_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 settings_service : ( unit , unit diff --git a/template.distillery/PROJECT_NAME_settings.eliom b/template.distillery/PROJECT_NAME_settings.eliom index ad8341f9..f0eb98ae 100644 --- a/template.distillery/PROJECT_NAME_settings.eliom +++ b/template.distillery/PROJECT_NAME_settings.eliom @@ -13,12 +13,12 @@ let%shared update_main_email_button email = ignore [%client (Lwt.async (fun () -> - Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) - (fun _ _ -> - let%lwt () = Os_current_user.update_main_email ~%email in - Eliom_client.change_page - ~service:%%%MODULE_NAME%%%_services.settings_service () ())) - : unit)]; + Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) + (fun _ _ -> + let%lwt () = Os_current_user.update_main_email ~%email in + Eliom_client.change_page + ~service:%%%MODULE_NAME%%%_services.settings_service () ())) + : unit)]; button (* A button to remove the email from the database *) @@ -32,12 +32,12 @@ let%shared delete_email_button email = ignore [%client (Lwt.async (fun () -> - Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) - (fun _ _ -> - let%lwt () = Os_current_user.remove_email_from_user ~%email in - Eliom_client.change_page - ~service:%%%MODULE_NAME%%%_services.settings_service () ())) - : unit)]; + Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) + (fun _ _ -> + let%lwt () = Os_current_user.remove_email_from_user ~%email in + Eliom_client.change_page + ~service:%%%MODULE_NAME%%%_services.settings_service () ())) + : unit)]; button (* A list of buttons to update or to remove the email depending on the @@ -93,8 +93,8 @@ let%rpc get_emails myid () : (string option * (string * bool) list) Lwt.t = let%lwt emails = Lwt_list.map_s (fun email -> - let%lwt v = Os_current_user.is_email_validated email in - Lwt.return (email, v)) + let%lwt v = Os_current_user.is_email_validated email in + Lwt.return (email, v)) emails in Lwt.return (main_email, emails) @@ -103,9 +103,7 @@ let%shared select_language_form select_language_name = let open Eliom_content.Html in let current_language = %%%MODULE_NAME%%%_i18n.get_language () in let all_languages_except_current = - List.filter - (fun l -> l <> current_language) - %%%MODULE_NAME%%%_i18n.languages + List.filter (fun l -> l <> current_language) %%%MODULE_NAME%%%_i18n.languages in let form_option_of_language language is_current_language = D.Form.Option diff --git a/template.distillery/demo.eliom b/template.distillery/demo.eliom index 997cd930..771dd124 100644 --- a/template.distillery/demo.eliom +++ b/template.distillery/demo.eliom @@ -18,26 +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 01e1cac7..c5bbc26f 100644 --- a/template.distillery/demo_cache.eliom +++ b/template.distillery/demo_cache.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 b1471b44..c4a05387 100644 --- a/template.distillery/demo_calendar.eliom +++ b/template.distillery/demo_calendar.eliom @@ -2,17 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 @@ -46,11 +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 63ba9ea1..fda89ae4 100644 --- a/template.distillery/demo_carousel1.eliom +++ b/template.distillery/demo_carousel1.eliom @@ -2,24 +2,10 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* Carousel demo *) - 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) @@ -37,7 +23,7 @@ let%shared bind_keys (* Do not forget to cancel the thread when we remove the carousel (here, when we go to another page): *) Eliom_client.onunload (fun () -> Lwt.cancel arrow_thread) - : unit)] + : unit)] (* Page for this demo *) let%shared page () = @@ -49,14 +35,14 @@ let%shared page () = let carousel_change_signal = [%client (React.E.create () - : ([`Goto of int | `Next | `Prev] as 'a) React.E.t - * (?step:React.step -> 'a -> unit))] + : ([`Goto of int | `Next | `Prev] as 'a) React.E.t + * (?step:React.step -> 'a -> unit))] in let update = [%client fst ~%carousel_change_signal] in let change = [%client (fun a -> snd ~%carousel_change_signal ?step:None a - : [`Goto of int | `Next | `Prev] -> unit)] + : [`Goto of int | `Next | `Prev] -> unit)] in let carousel_pages = ["1"; "2"; "3"; "4"] in let length = List.length carousel_pages in @@ -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 2143e229..e4a1604c 100644 --- a/template.distillery/demo_carousel2.eliom +++ b/template.distillery/demo_carousel2.eliom @@ -2,7 +2,6 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* Page with several tabs *) - open Eliom_content.Html] [%%shared open Eliom_content.Html.F] @@ -21,19 +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 = @@ -46,8 +32,8 @@ let%shared page () = let carousel_change_signal = [%client (React.E.create () - : ([`Goto of int | `Next | `Prev] as 'a) React.E.t - * (?step:React.step -> 'a -> unit))] + : ([`Goto of int | `Next | `Prev] as 'a) React.E.t + * (?step:React.step -> 'a -> unit))] in let update = [%client fst ~%carousel_change_signal] in let change = [%client fun a -> snd ~%carousel_change_signal ?step:None a] in @@ -82,9 +68,9 @@ let%shared page () = ignore [%client (Lwt.async (fun () -> - Lwt.map ignore - (Ot_sticky.make_sticky ~ios_html_scroll_hack:true ~dir:`Top ~%tabs)) - : unit)]; + Lwt.map ignore + (Ot_sticky.make_sticky ~ios_html_scroll_hack:true ~dir:`Top ~%tabs)) + : unit)]; Lwt.return [ h1 [%i18n Demo.carousel_2] ; p [%i18n Demo.ot_carousel_second_example_1] @@ -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 3e413d71..9f6adaa9 100644 --- a/template.distillery/demo_carousel3.eliom +++ b/template.distillery/demo_carousel3.eliom @@ -2,24 +2,10 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* Wheel demo *) - 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 = @@ -64,8 +50,8 @@ let%shared page () = let carousel_change_signal = [%client (React.E.create () - : ([`Goto of int | `Next | `Prev] as 'a) React.E.t - * (?step:React.step -> 'a -> unit))] + : ([`Goto of int | `Next | `Prev] as 'a) React.E.t + * (?step:React.step -> 'a -> unit))] in let update = [%client fst ~%carousel_change_signal] in let change = [%client fun a -> snd ~%carousel_change_signal ?step:None a] in @@ -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 da86e914..95ecd1c3 100644 --- a/template.distillery/demo_i18n.eliom +++ b/template.distillery/demo_i18n.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 561613c6..66eb07c9 100644 --- a/template.distillery/demo_links.eliom +++ b/template.distillery/demo_links.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 9e7f8f91..80f82f58 100644 --- a/template.distillery/demo_notif.eliom +++ b/template.distillery/demo_notif.eliom @@ -4,18 +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. @@ -24,13 +14,13 @@ let%shared page_class = "os-page-demo-notif" (for example type key = int64). *) module Notif = Os_notif.Make_Simple (struct - type key = unit + type key = unit - (* The resources identifiers. + (* The resources identifiers. Here unit because we have only one resource. *) - type notification = string -end) + type notification = string + end) (* Broadcast message [v] *) let%rpc notify (v : string) : unit Lwt.t = @@ -50,18 +40,18 @@ let%rpc listen () : unit Lwt.t = Notif.listen (); Lwt.return_unit happens. *) let%server () = Os_session.on_start_process (fun _ -> - let e : (unit * string) Eliom_react.Down.t = Notif.client_ev () in - ignore - [%client - (Eliom_lib.Dom_reference.retain Js_of_ocaml.Dom_html.window - ~keep: - (React.E.map - (fun (_, msg) -> - (* Eliom_lib.alert "%s" msg *) - Os_msg.msg ~level:`Msg (Printf.sprintf "%s" msg)) - ~%e) - : unit)]; - Lwt.return_unit) + let e : (unit * string) Eliom_react.Down.t = Notif.client_ev () in + ignore + [%client + (Eliom_lib.Dom_reference.retain Js_of_ocaml.Dom_html.window + ~keep: + (React.E.map + (fun (_, msg) -> + (* Eliom_lib.alert "%s" msg *) + Os_msg.msg ~level:`Msg (Printf.sprintf "%s" msg)) + ~%e) + : unit)]; + Lwt.return_unit) (* Make a text input field that calls [f s] for each [s] submitted *) let%shared make_form msg f = @@ -79,7 +69,7 @@ let%shared make_form msg f = let%lwt () = ~%f v in inp##.value := Js_of_ocaml.Js.string ""; Lwt.return_unit - : unit)]; + : unit)]; Eliom_content.Html.D.div [inp; btn] let%rpc unlisten () : unit Lwt.t = Notif.unlisten (); Lwt.return_unit @@ -104,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 cc4a3a02..a97c0504 100644 --- a/template.distillery/demo_pagetransition.eliom +++ b/template.distillery/demo_pagetransition.eliom @@ -13,26 +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 @@ -40,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 = @@ -67,9 +49,9 @@ let%shared page () = !r in Lwt_js_events.clicks (To_dom.of_element ~%add_button) (fun _ _ -> - Html.Manip.appendChild ~%l (create_item (counter ())); - Lwt.return_unit) - : unit Lwt.t)]; + Html.Manip.appendChild ~%l (create_item (counter ())); + Lwt.return_unit) + : unit Lwt.t)]; Lwt.return [ h1 [%i18n Demo.pagetransition_list_page] ; p [%i18n Demo.pagetransition_intro] @@ -83,11 +65,32 @@ let%shared make_detail_page page () = ignore [%client (Lwt.async (fun () -> - Lwt_js_events.clicks (To_dom.of_element ~%back_button) (fun _ _ -> - Js_of_ocaml.Dom_html.window##.history##back; - Lwt.return_unit)) - : unit)]; + Lwt_js_events.clicks (To_dom.of_element ~%back_button) (fun _ _ -> + Js_of_ocaml.Dom_html.window##.history##back; + Lwt.return_unit)) + : unit)]; [ h1 ([%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 b1c6e4ae..393f3262 100644 --- a/template.distillery/demo_pgocaml.eliom +++ b/template.distillery/demo_pgocaml.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 4cfeb736..e5ec15e3 100644 --- a/template.distillery/demo_popup.eliom +++ b/template.distillery/demo_popup.eliom @@ -2,24 +2,13 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* Popup button demo *) - 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). *) @@ -52,17 +41,28 @@ let%shared page () = (* This client section will be executed after the page is displayed by the browser. *) (Lwt.async (fun () -> - (* Lwt_js_events.clicks returns a Lwt thread, which never terminates. + (* Lwt_js_events.clicks returns a Lwt thread, which never terminates. We run it asynchronously. *) - Lwt_js_events.clicks (To_dom.of_element ~%button) (fun _ _ -> - let%lwt _ = - Ot_popup.popup ~close_button:[Os_icons.F.close ()] (fun _ -> - Lwt.return @@ p [%i18n Demo.popup_message]) - in - Lwt.return_unit)) - : unit)]; + Lwt_js_events.clicks (To_dom.of_element ~%button) (fun _ _ -> + let%lwt _ = + Ot_popup.popup + ~close_button:[Os_icons.F.close ()] + (fun _ -> Lwt.return @@ p [%i18n Demo.popup_message]) + in + Lwt.return_unit)) + : unit)]; (* Page elements, using module Eliom_content.Html.F (as we don't want to add a unique identifier). 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 a65e9e05..75d04ec5 100644 --- a/template.distillery/demo_pulltorefresh.eliom +++ b/template.distillery/demo_pulltorefresh.eliom @@ -4,19 +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 @@ -45,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 38ed9a55..2be82041 100644 --- a/template.distillery/demo_react.eliom +++ b/template.distillery/demo_react.eliom @@ -4,19 +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 = @@ -34,7 +23,7 @@ let%shared make_form msg f = let%lwt () = ~%f v in inp##.value := Js_of_ocaml.Js.string ""; Lwt.return_unit - : unit)]; + : unit)]; Eliom_content.Html.D.div [inp; btn] (* Page for this demo *) @@ -51,7 +40,7 @@ let%shared page () = make_form [%i18n Demo.S.reactive_programming_button] [%client (fun v -> Lwt.return (Eliom_shared.ReactiveData.RList.cons v ~%h) - : string -> unit Lwt.t)] + : string -> unit Lwt.t)] and l = (* Produce
  • items from l contents. The shared function will first be called once server or client-side @@ -70,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 e0759751..3ef18367 100644 --- a/template.distillery/demo_ref.eliom +++ b/template.distillery/demo_ref.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 1ece9ccb..781e8692 100644 --- a/template.distillery/demo_rpc.eliom +++ b/template.distillery/demo_rpc.eliom @@ -2,27 +2,16 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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). It's also possible to define Eliom references with other scopes, like client-process (a tab of a browser) or session-group (a user). - *) +*) let%server my_ref = Eliom_reference.eref ~scope:Eliom_common.default_session_scope 0 @@ -42,7 +31,7 @@ let%shared button msg f = (Lwt.async @@ fun () -> Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%btn) (fun _ _ -> ~%f ()) - : unit)]; + : unit)]; btn (* Page for this demo *) @@ -54,10 +43,20 @@ let%shared page () = let%lwt v = incr_my_ref () in Eliom_lib.alert "Update: %d" v; Lwt.return_unit - : unit -> unit Lwt.t)] + : unit -> unit Lwt.t)] in Lwt.return Eliom_content.Html. [ 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 a5affc2a..57b69088 100644 --- a/template.distillery/demo_spinner.eliom +++ b/template.distillery/demo_spinner.eliom @@ -2,21 +2,10 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 397dc5e2..6e081dc7 100644 --- a/template.distillery/demo_timepicker.eliom +++ b/template.distillery/demo_timepicker.eliom @@ -7,14 +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) = @@ -32,11 +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 = @@ -48,9 +35,9 @@ let%shared page () = ignore [%client (Lwt.async (fun () -> - Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) - (fun _ _ -> ~%back_f (); Lwt.return_unit)) - : _)]; + Lwt_js_events.clicks (Eliom_content.Html.To_dom.of_element ~%button) + (fun _ _ -> ~%back_f (); Lwt.return_unit)) + : _)]; let%lwt tr = time_reactive () in Lwt.return [ h1 [%i18n Demo.timepicker] @@ -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 d29d6b8e..862d7853 100644 --- a/template.distillery/demo_tips.eliom +++ b/template.distillery/demo_tips.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 27c407c3..3181dc6a 100644 --- a/template.distillery/demo_tongue.eliom +++ b/template.distillery/demo_tongue.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 362e80e0..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 fd04ebac..8a19c0d8 100644 --- a/template.distillery/demo_users.eliom +++ b/template.distillery/demo_users.eliom @@ -2,22 +2,8 @@ (* This file was generated by Ocsigen Start. Feel free to use it, modify it, and redistribute it as you wish. *) (* 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 )