Gitlab is now running v13.9.0 - More info -> here <-

Commit f3da8080 authored by Philippe Veber's avatar Philippe Veber

tk/Dataframe.to_html: added argument for custom table cell renderi

parent 625c0855
......@@ -140,11 +140,20 @@ let from_file ?(header = `Read_in_file) path =
let cols = List.zip_exn labels cols in
Ok { nrows ; ncols ; cols }
let to_html d =
let to_html ?(cell_renderers = []) d =
let open Tyxml.Html in
let default_cell s = txt s in
let cols = List.map d.cols ~f:(fun (label, col) ->
let cell_renderer =
List.Assoc.find cell_renderers ~equal:String.equal label
|> Option.value ~default:default_cell
in
label, cell_renderer, col
)
in
let thead =
thead [
tr (List.map d.cols ~f:(fun (label, _) -> td [txt label]))
tr (List.map cols ~f:(fun (label, _, _) -> td [txt label]))
]
in
let elem col i =
......@@ -158,7 +167,7 @@ let to_html d =
| String_opts t -> Option.value ~default t.(i)
in
let row i =
List.map d.cols ~f:(fun (_, col) -> td [txt (elem col i)])
List.map cols ~f:(fun (_, renderer, col) -> td [renderer (elem col i)])
|> tr
in
table ~thead (List.init (nrows d) ~f:row)
......@@ -24,4 +24,10 @@ val from_file :
string ->
(t, [> `Msg of string]) result
val to_html : t -> [> Html_types.table ] Tyxml.Html.elt
val to_html :
?cell_renderers:
(string *
(string -> [< Html_types.td_content > `PCDATA] Tyxml.Html.elt))
list ->
t ->
[> Html_types.table ] Tyxml.Html.elt
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment