Skip to content

Commit

Permalink
Template: simplifying demo's code
Browse files Browse the repository at this point in the history
Removing first class modules to make the code easier to read for beginners
Making the code more canonical
  • Loading branch information
balat committed Feb 18, 2024
1 parent 8327946 commit 56b1056
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 355 deletions.
3 changes: 1 addition & 2 deletions template.distillery/PROJECT_NAME.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 0 additions & 4 deletions template.distillery/PROJECT_NAME_services.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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) ()
Expand Down
21 changes: 1 addition & 20 deletions template.distillery/demo.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 10 additions & 14 deletions template.distillery/demo_cache.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_calendar.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_carousel1.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_carousel2.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_carousel3.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_i18n.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
24 changes: 10 additions & 14 deletions template.distillery/demo_links.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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:[]
Expand Down Expand Up @@ -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 )
25 changes: 12 additions & 13 deletions template.distillery/demo_notif.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 )
Loading

0 comments on commit 56b1056

Please sign in to comment.