Skip to content

Commit 5116f45

Browse files
cuihtlauacCuihtlauac ALVARADO
and
Cuihtlauac ALVARADO
authored
chore: Single data_intf.ml type definition for Academic_Institution (#2477)
* Data intf module * Single type for Academic_institution --------- Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
1 parent 4f06cdc commit 5116f45

File tree

6 files changed

+43
-71
lines changed

6 files changed

+43
-71
lines changed

src/ocamlorg_data/data.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module Academic_institution = struct
2+
include Data_intf.Academic_institution
23
include Academic_institution
34

45
let get_by_slug slug = List.find_opt (fun x -> String.equal slug x.slug) all

src/ocamlorg_data/data.mli

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
module Academic_institution : sig
2-
type location = { lat : float; long : float }
3-
4-
type course = {
5-
name : string;
6-
acronym : string option;
7-
online_resource : string option;
8-
}
9-
10-
type t = {
11-
name : string;
12-
slug : string;
13-
description : string;
14-
url : string;
15-
logo : string option;
16-
continent : string;
17-
courses : course list;
18-
location : location option;
19-
body_md : string;
20-
body_html : string;
21-
}
2+
include module type of Data_intf.Academic_institution
223

234
val all : t list
245
val get_by_slug : string -> t option

src/ocamlorg_data/data_intf.ml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Academic_institution = struct
2+
type location = { lat : float; long : float } [@@deriving of_yaml, show]
3+
4+
type course = {
5+
name : string;
6+
acronym : string option;
7+
online_resource : string option;
8+
}
9+
[@@deriving of_yaml, show]
10+
11+
type t = {
12+
name : string;
13+
slug : string;
14+
description : string;
15+
url : string;
16+
logo : string option;
17+
continent : string;
18+
courses : course list;
19+
location : location option;
20+
body_md : string;
21+
body_html : string;
22+
}
23+
[@@deriving show]
24+
end

src/ocamlorg_data/dune

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
(library
2+
(name data_intf)
3+
(public_name ocamlorg.data_intf)
4+
(modules data_intf)
5+
(libraries ppx_show.runtime)
6+
(preprocess
7+
(pps ppx_deriving_yaml ppx_show)))
8+
19
(library
210
(name data)
3-
(public_name ocamlorg.data))
11+
(public_name ocamlorg.data)
12+
(libraries ocamlorg.data_intf)
13+
(modules
14+
(:standard \ data_intf)))
415

516
(rule
617
(target academic_institution.ml)

tool/ood-gen/lib/academic_institution.ml

+4-50
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
type location = { lat : float; long : float }
2-
[@@deriving of_yaml, show { with_path = false }]
3-
4-
type course = {
5-
name : string;
6-
acronym : string option;
7-
online_resource : string option;
8-
}
9-
[@@deriving of_yaml, show { with_path = false }]
1+
open Data_intf.Academic_institution
102

113
type metadata = {
124
name : string;
@@ -17,25 +9,9 @@ type metadata = {
179
courses : course list;
1810
location : location option;
1911
}
20-
[@@deriving of_yaml]
12+
[@@deriving of_yaml, stable_record ~version:t ~add:[ body_md; body_html; slug ]]
2113

22-
type t = {
23-
name : string;
24-
slug : string;
25-
description : string;
26-
url : string;
27-
logo : string option;
28-
continent : string;
29-
courses : course list;
30-
location : location option;
31-
body_md : string;
32-
body_html : string;
33-
}
34-
[@@deriving
35-
stable_record ~version:metadata ~remove:[ body_md; body_html; slug ],
36-
show { with_path = false }]
37-
38-
let of_metadata m = of_metadata m ~slug:(Utils.slugify m.name)
14+
let of_metadata m = metadata_to_t m ~slug:(Utils.slugify m.name)
3915

4016
let decode (fpath, (head, body_md)) =
4117
let metadata =
@@ -49,29 +25,7 @@ let decode (fpath, (head, body_md)) =
4925
let all () = Utils.map_files decode "academic_institutions/*.md"
5026

5127
let template () =
52-
Format.asprintf
53-
{|
54-
type location = { lat : float; long : float }
55-
56-
type course =
57-
{ name : string
58-
; acronym : string option
59-
; online_resource : string option
60-
}
61-
62-
type t =
63-
{ name : string
64-
; slug : string
65-
; description : string
66-
; url : string
67-
; logo : string option
68-
; continent : string
69-
; courses : course list
70-
; location : location option
71-
; body_md : string
72-
; body_html : string
73-
}
74-
28+
Format.asprintf {|
7529
let all = %a
7630
|}
7731
(Fmt.brackets (Fmt.list pp ~sep:Fmt.semi))

tool/ood-gen/lib/dune

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(libraries
44
bos
55
ocamlorg.global
6+
ocamlorg.data_intf
67
cmarkit
78
yaml
89
unix

0 commit comments

Comments
 (0)