From 841e0f74591261ac9046b22b0d6d43191fbebec1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Am=C3=A9lia=20Coutard-Sander?= Date: Sun, 15 Feb 2026 02:28:57 +0100 Subject: [PATCH] Le fichier style.css est maintenant *vraiment* du OCaml --- f4mnq/dune | 3 ++- f4mnq/style.ml | 51 ++++++++++++++++++-------------------------------- html/CSS.ml | 40 +++++++++++++++++++++++++++++++++++++++ html/CSS.mli | 34 +++++++++++++++++++++++++++++++++ html/dune | 2 ++ 5 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 html/CSS.ml create mode 100644 html/CSS.mli create mode 100644 html/dune diff --git a/f4mnq/dune b/f4mnq/dune index 4d37451..e174c57 100644 --- a/f4mnq/dune +++ b/f4mnq/dune @@ -1,5 +1,6 @@ (executables - (public_names index style)) + (public_names index style) + (libraries html)) (install (files diff --git a/f4mnq/style.ml b/f4mnq/style.ml index 2c79b04..5900d65 100644 --- a/f4mnq/style.ml +++ b/f4mnq/style.ml @@ -15,38 +15,23 @@ * along with this website. If not, see . *) -Printf.printf "%s" - {|@media (prefers-color-scheme: light) { -body { - background-color: #ffc; - color: #000; -} -a { - color: #099; -} -a:visited { - color: #c3c; -} -} -@media (prefers-color-scheme: dark) { -body { - background-color: #003; - color: #fff; -} -a { - color: #ff9; -} -a:visited { - color: #f99; -} -} +open Html -#content { - min-height: calc(100vh - 200px); -} +let colorscheme ~scheme ~fg ~bg ~link ~used_link = + let open CSS in + media ~feature:("prefers-color-scheme", scheme) + [ + block [tag "body"] [property "background-color" ("#" ^ bg); property "color" ("#" ^ fg)]; + block [tag "a"] [property "color" ("#" ^ link)]; + block [tag "a:visited"] [property "color" ("#" ^ used_link)]; + ] -#mpring { - margin-left: calc(50% - 100px); - border: 0; -} -|} +let () = + let open CSS in + CSS.print + [ + colorscheme ~scheme:"light" ~fg:"000" ~bg:"ffc" ~link:"099" ~used_link:"c3c"; + colorscheme ~scheme:"dark" ~fg:"fff" ~bg:"003" ~link:"ff9" ~used_link:"f99"; + block [id "content"] [property "min-height" "calc(100vh - 200px)"]; + block [id "mpring"] [property "margin-left" "calc(50% - 100px)"; property "border" "0"]; + ] diff --git a/html/CSS.ml b/html/CSS.ml new file mode 100644 index 0000000..78ed2d6 --- /dev/null +++ b/html/CSS.ml @@ -0,0 +1,40 @@ +(* f4mnq.fr + * Copyright 2026 Amélia COUTARD-SANDER . + + * This website is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + + * This website is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this website. If not, see . + *) + +type t = string -> unit + +type selector = string + +type property = string -> unit + +let print = List.iter (fun f -> f "") + +let media ~feature:(n, v) blocks indent = + Printf.printf "%s@media (%s: %s) {\n" indent n v; + List.iter (fun f -> f indent) blocks; + Printf.printf "%s}\n" indent + +let block selectors properties indent = + Printf.printf "%s%s {\n" indent (String.concat " " selectors); + List.iter (fun f -> f @@ indent ^ "\t") properties; + Printf.printf "%s}\n" indent + +let tag s = s + +let id s = "#" ^ s + +let property name value indent = Printf.printf "%s%s: %s;\n" indent name value diff --git a/html/CSS.mli b/html/CSS.mli new file mode 100644 index 0000000..da0b487 --- /dev/null +++ b/html/CSS.mli @@ -0,0 +1,34 @@ +(* f4mnq.fr + * Copyright 2026 Amélia COUTARD-SANDER . + + * This website is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + + * This website is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this website. If not, see . + *) + +type t + +type selector + +type property + +val print : t list -> unit + +val media : feature:string * string -> t list -> t + +val block : selector list -> property list -> t + +val tag : string -> selector + +val id : string -> selector + +val property : string -> string -> property diff --git a/html/dune b/html/dune new file mode 100644 index 0000000..d3de825 --- /dev/null +++ b/html/dune @@ -0,0 +1,2 @@ +(library + (name html)) -- 2.52.0