package ppx_css

  1. Overview
  2. Docs
A ppx that takes in css strings and produces a module for accessing the unique names defined within

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_css-v0.16.0.tar.gz
sha256=58a8f237e28c0f223e85552f0f1097c9f7a9682fccee61c593dae32c506926ae

doc/src/ppx_css.inline_css/style_element_strategy.ml.html

Source file style_element_strategy.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
open! Core
open Js_of_ocaml

module Make (T : sig
    val name : string
    val parent_selector : string
  end) =
struct
  include T

  type t = Dom_html.styleElement Js.t

  let make_style_element () = Dom_html.createStyle Dom_html.document
  let update t content = t##.innerText := Js.string content

  let initialize () =
    let parent = Dom_html.document##querySelector (Js.string parent_selector) in
    match Js.Opt.to_option parent with
    | None -> Or_error.error_string (parent_selector ^ " not found in document")
    | Some parent ->
      (try
         let style_element = make_style_element () in
         ignore (parent##appendChild (style_element :> Dom.node Js.t));
         Ok style_element
       with
       | exn -> Or_error.of_exn exn)
  ;;
end

module Into_head = Make (struct
    let name = "<style> element inside <head> element"
    let parent_selector = "head"
  end)

module Into_body = Make (struct
    let name = "<style> element inside <body> element"
    let parent_selector = "body"
  end)

module Into_root_element = Make (struct
    let name = "any element inside the document"
    let parent_selector = "*"
  end)
OCaml

Innovation. Community. Security.