Skip to content

Commit

Permalink
Merge pull request #673 from ocsigen/simpldemo
Browse files Browse the repository at this point in the history
Simplify demo
  • Loading branch information
balat authored Feb 18, 2024
2 parents 3f95743 + 8d7ed30 commit bc26150
Show file tree
Hide file tree
Showing 37 changed files with 552 additions and 549 deletions.
2 changes: 1 addition & 1 deletion opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "ocsigen-start"
version: "6.1.2"
version: "6.2.0"
authors: "[email protected]"
maintainer: "[email protected]"
synopsis: "Higher-level library for developing Web and mobile applications with users, registration, notifications, etc"
Expand Down
29 changes: 11 additions & 18 deletions template.distillery/PROJECT_NAME.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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 <debugmode/> is in config file
(DEBUG = yes in Makefile.options).
Expand All @@ -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 (
Expand All @@ -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
Expand All @@ -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
17 changes: 6 additions & 11 deletions template.distillery/PROJECT_NAME_base.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]")
let () = Os_email.set_from_addr ("%%%PROJECT_NAME%%% team", "[email protected]")

(* 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 <head> of the page when changing page. (This also avoids
Expand Down
15 changes: 7 additions & 8 deletions template.distillery/PROJECT_NAME_config.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand All @@ -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 ()

Expand Down
10 changes: 5 additions & 5 deletions template.distillery/PROJECT_NAME_container.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions template.distillery/PROJECT_NAME_drawer.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
17 changes: 7 additions & 10 deletions template.distillery/PROJECT_NAME_handlers.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
38 changes: 18 additions & 20 deletions template.distillery/PROJECT_NAME_language.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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)
47 changes: 23 additions & 24 deletions template.distillery/PROJECT_NAME_mobile.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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 *)

Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions template.distillery/PROJECT_NAME_page.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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)]
Loading

0 comments on commit bc26150

Please sign in to comment.