Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/os_page.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module type PAGE = sig
val local_js : string list list
val css : string list list
val local_css : string list list
val other_head : Html_types.head_content_fun Eliom_content.Html.elt list
val other_head : unit -> Html_types.head_content_fun Eliom_content.Html.elt list
val default_error_page : 'a -> 'b -> exn -> content Lwt.t

val default_connected_error_page :
Expand All @@ -76,7 +76,7 @@ module Default_config = struct
let css : string list list = []
let local_js : string list list = []
let local_css : string list list = []
let other_head : Html_types.head_content_fun Eliom_content.Html.elt list = []
let other_head () : Html_types.head_content_fun Eliom_content.Html.elt list = []

let err_page exn =
let de =
Expand Down Expand Up @@ -144,7 +144,7 @@ module Make (C : PAGE) = struct
in
html ~a:content.html_attrs
(Eliom_tools.F.head ~title ~css ~js
~other:(local_css @ local_js @ content.head @ C.other_head)
~other:(local_css @ local_js @ content.head @ C.other_head ())
())
(body
~a:(platform_attr :: connected_attr :: content.body_attrs)
Expand Down
2 changes: 1 addition & 1 deletion src/os_page.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module type PAGE = sig
a mobile application.
Os will automatically prepend the suffix ["css/"] as directory. *)

val other_head : Html_types.head_content_fun Eliom_content.Html.elt list
val other_head : unit -> Html_types.head_content_fun Eliom_content.Html.elt list
(** [other_head] is a list of custom elements to add in the head section.
It can be used to add <meta> elements, for example. *)

Expand Down
3 changes: 3 additions & 0 deletions template.distillery/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ SASS_PATH := $(SASSDIR)/lib:$(LOCAL_STATIC_CSS)
# JavaScript, ocsigenserver
DEBUG := yes

# Enable WASM compilation (yes/no): Requires wasm_of_ocaml (enabled by default)
USE_WASM := yes

##----------------------------------------------------------------------

##----------------------------------------------------------------------
Expand Down
25 changes: 23 additions & 2 deletions template.distillery/Makefile.os
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(FILESDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js && \
if [ "$(USE_WASM)" = "yes" ]; then \
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).wasm.js && \
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(PREFIX)$(ELIOMSTATICDIR)/; \
fi; \
fi
HASH=`cat $(LOCAL_CSS) | md5sum | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(CSS_PREFIX)_$$HASH.css $(PREFIX)$(ELIOMSTATICDIR)/css && \
ln -sf $(PROJECT_NAME)_$$HASH.css $(PREFIX)$(ELIOMSTATICDIR)/css/$(PROJECT_NAME).css
Expand Down Expand Up @@ -156,6 +164,11 @@ SED_ARGS += -e "s|%%FILESDIR%%|%%PREFIX%%$(FILESDIR)|g"
SED_ARGS += -e "s|%%ELIOMSTATICDIR%%|%%PREFIX%%$(ELIOMSTATICDIR)|g"
SED_ARGS += -e "s|%%APPNAME%%|$(shell basename `readlink $(JS_PREFIX).js` .js)|g"
SED_ARGS += -e "s|%%CSSNAME%%|$(shell readlink $(CSS_PREFIX).css)|g"
ifeq ($(USE_WASM),yes)
SED_ARGS += -e "s|%%WASMATTR%%|wasm=\"$(shell basename `readlink $(JS_PREFIX).wasm.js` .wasm.js).wasm.js\"|g"
else
SED_ARGS += -e "s|%%WASMATTR%%||g"
endif
ifeq ($(DEBUG),yes)
SED_ARGS += -e "s|%%DEBUGMODE%%|\<debugmode /\>|g"
else
Expand Down Expand Up @@ -189,7 +202,15 @@ $(TEST_CONFIG_FILES): $(TEST_PREFIX)$(ETCDIR)/%-test.conf: %.conf.in $(JS_AND_CS
config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.js $(JS_PREFIX)_$$HASH.js && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(JS_PREFIX).js
ln -sf $(PROJECT_NAME)_$$HASH.js $(JS_PREFIX).js && \
if [ "$(USE_WASM)" = "yes" ]; then \
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.wasm.js $(JS_PREFIX)_$$HASH_WASM.wasm.js && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(JS_PREFIX).wasm.js && \
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(TEST_PREFIX)$(ELIOMSTATICDIR)/; \
fi; \
fi
cp -f _build/default/$(PROJECT_NAME).cm* $(TEST_PREFIX)$(LIBDIR)/
$(MAKE) $(CONFIG_FILES) $(TEST_CONFIG_FILES) PROJECT_NAME=$(PROJECT_NAME)

Expand Down
4 changes: 3 additions & 1 deletion template.distillery/PROJECT_NAME.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<extension findlib-package="eliom.server">
<!-- Ask Eliom to ignore UTM parameters and others: -->
<ignoredgetparams regexp="utm_[a-z]*|[a-z]*clid|li_fat_id"/>
<!-- Enable WebAssembly support with automatic browser detection: -->
<wasm enabled="true"/>
<!-- Uncomment if you are using https only and want secure cookies:
<securecookies value="true" />
-->
Expand All @@ -54,7 +56,7 @@
<static dir="%%FILESDIR%%" />
%%ELIOM_MODULES%%
<eliommodule module="%%LIBDIR%%/%%PROJECT_NAME%%.cma">
<app name="%%APPNAME%%" css="%%CSSNAME%%" />
<app name="%%APPNAME%%" css="%%CSSNAME%%" %%WASMATTR%% />
<avatars dir="%%FILESDIR%%/avatars" />
<os-db
host="%%DB_HOST%%"
Expand Down
4 changes: 3 additions & 1 deletion template.distillery/PROJECT_NAME_config.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

let app_name = ref ""
let css_name = ref ""
let wasm_name = ref ""

(* The name of the avatar directory. *)
let avatar_dir = ref []
Expand All @@ -38,7 +39,8 @@ let app =
let open Ocsigen_extensions.Configuration in
let attributes =
[ attribute ~name:"name" ~obligatory:true (fun h -> app_name := h)
; attribute ~name:"css" ~obligatory:true (fun h -> css_name := h) ]
; attribute ~name:"css" ~obligatory:true (fun h -> css_name := h)
; attribute ~name:"wasm" (fun h -> wasm_name := h) ]
in
element ~name:"app" ~obligatory:true ~attributes ()

Expand Down
1 change: 1 addition & 0 deletions template.distillery/PROJECT_NAME_config.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

val app_name : string ref
val css_name : string ref
val wasm_name : string ref
val avatar_dir : string list ref
val os_db_host : string option ref
val os_db_port : int option ref
Expand Down
31 changes: 27 additions & 4 deletions template.distillery/PROJECT_NAME_page.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,33 @@ let%server css_name_script =

let%client css_name_script = []

let%server wasm_name = !%%%MODULE_NAME%%%_config.wasm_name

let%client wasm_name =
try Js_of_ocaml.Js.to_string Js_of_ocaml.Js.Unsafe.global##.___wasm_name_
with _ -> ""

let%server wasm_name_script =
[script (cdata_script (Printf.sprintf "var __wasm_name = '%s';" wasm_name))]

let%client wasm_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%client app_js = []
let%server app_js () =
if wasm_name <> "" && (Eliom_request_info.get_sitedata ()).Eliom_common.enable_wasm
then
(* Use WASM detection script with hashed filenames *)
let app_name = !%%%MODULE_NAME%%%_config.app_name in
[%%%MODULE_NAME%%%_base.App.wasm_detection_script
~defer:true
~js_name:(app_name ^ ".js")
~wasm_name
()]
else [%%%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 *)
let%shared the_local_css = [[css_name]]
Expand All @@ -33,14 +55,15 @@ module%shared Page_config = struct
let local_js = the_local_js
let local_css = the_local_css

let other_head =
let other_head () =
meta
~a:
[ a_name "viewport"
; a_content "width=device-width, initial-scale=1, user-scalable=no" ]
()
:: css_name_script
@ app_js
@ wasm_name_script
@ app_js ()

let default_predicate _ _ = Lwt.return_true
let default_connected_predicate _ _ _ = Lwt.return_true
Expand Down
6 changes: 4 additions & 2 deletions template.distillery/PROJECT_NAME_page.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

val%shared css_name : string
val%shared css_name_script : [> Html_types.script] Eliom_content.Html.F.elt list
val%shared app_js : [> `Script] Eliom_content.Html.elt list
val%shared wasm_name : string
val%shared wasm_name_script : [> Html_types.script] Eliom_content.Html.F.elt list
val%shared app_js : unit -> [> `Script] Eliom_content.Html.elt list
val%shared the_local_js : 'a list
val%shared the_local_css : string list list

Expand All @@ -13,7 +15,7 @@ module%shared Page_config : sig
val title : string
val local_js : 'a list
val local_css : string list list
val other_head : [> Html_types.head_content] Eliom_content.Html.F.elt list
val other_head : unit -> Html_types.head_content_fun Eliom_content.Html.elt list
val default_predicate : 'a -> 'b -> bool Lwt.t
val default_connected_predicate : 'a -> 'b -> 'c -> bool Lwt.t
val default_error_page : 'a -> 'b -> exn -> Os_page.content Lwt.t
Expand Down
10 changes: 9 additions & 1 deletion template.distillery/dune
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
client
(executables
(names %%%PROJECT_NAME%%%)
(modes js byte)
(modes js byte wasm)
(preprocess
(pps
js_of_ocaml-ppx
Expand All @@ -151,6 +151,13 @@
use-js-string
--no-source-map))
; source maps are slow...
(wasm_of_ocaml
(flags
:standard
--enable
use-js-string
--enable
with-js-error))
(libraries eliom.client ocsigen-start.client))
(dynamic_include ../gen/dune.client))

Expand All @@ -162,6 +169,7 @@
%%%PROJECT_NAME%%%.cma
client/%%%PROJECT_NAME%%%.bc
client/%%%PROJECT_NAME%%%.bc.js
client/%%%PROJECT_NAME%%%.bc.wasm.js
tools/check_modules.ml)
(action
(run ocaml -I +unix -I +str tools/check_modules.ml %%%PROJECT_NAME%%%)))
2 changes: 1 addition & 1 deletion template.distillery/dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 3.14)
(lang dune 3.19)

(dialect
(name "eliom-server")
Expand Down
Loading