aboutsummaryrefslogtreecommitdiff
path: root/elements
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-02-04 21:14:01 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 14:37:57 +0100
commit86ec559f913c389e8dc055b494630f21a45e039b (patch)
tree822341b481695c9bf8b39f8b8fcbdeef56e629d6 /elements
parent03f8a08fe2dde9db9fb656dbea2e5494b67236ad (diff)
css_merge application
Diffstat (limited to 'elements')
-rwxr-xr-xelements/dune2
-rwxr-xr-xelements/transfert.ml22
2 files changed, 24 insertions, 0 deletions
diff --git a/elements/dune b/elements/dune
index 755bd05..97d0753 100755
--- a/elements/dune
+++ b/elements/dune
@@ -3,5 +3,7 @@
(libraries
brr
brr.note
+ js_of_ocaml
)
+ (preprocess (pps ppx_hash js_of_ocaml-ppx))
)
diff --git a/elements/transfert.ml b/elements/transfert.ml
new file mode 100755
index 0000000..ddeecd0
--- /dev/null
+++ b/elements/transfert.ml
@@ -0,0 +1,22 @@
+open Js_of_ocaml
+open Brr
+
+let send
+ : mime_type:Jstr.t -> filename:Jstr.t -> Jstr.t -> unit
+ = fun ~mime_type ~filename content ->
+ let btoa = Jv.get Jv.global "btoa" in
+ let base64data = Jv.apply btoa
+ [| Jv.of_jstr content |] in
+
+ let mime = (Jv.Id.(of_jv @@ to_jv mime_type))
+ and base64 = (Jv.Id.(of_jv @@ to_jv base64data))
+ in
+
+ let data = (Js.string "data:")##concat_3 mime (Js.string ";base64,") base64 in
+
+ (* Create the link to download the the element, and simulate a click on it *)
+ let a = El.a
+ ~at:At.[ href Jv.Id.(of_jv @@ to_jv data)
+ ; v (Jstr.v "download") filename ]
+ [] in
+ El.click a