From 86ec559f913c389e8dc055b494630f21a45e039b Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 4 Feb 2021 21:14:01 +0100 Subject: css_merge application --- elements/dune | 2 ++ elements/transfert.ml | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 elements/transfert.ml (limited to 'elements') 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 -- cgit v1.2.3