/
opaDocUtils.opa
94 lines (79 loc) · 2.33 KB
/
opaDocUtils.opa
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA 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 OPA. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* {1 Utils for generation}
*
**/
OpaDocUtils = {{
/**
* Build the xhtml concatenation from the elements of a list.
**/
fold_xhtml(f, l) = List.fold_left((acc, x -> <>{acc}{f(x)}</>),<></>, l)
sanitize_path(path) =
aux(c, acc) =
r =
match c with
//delim
| ">" -> "sup"
| "<" -> "inf"
| "#" -> "sharp"
| "%" -> "percent"
// unwise
| "^" -> "hat"
| "`" -> "bkquote"
| "|" -> "pipe"
| s -> s
end
acc^r
String.fold(aux, path, "")
/**
* Given an entry, tell if the entry is private, meaning that it should not be displayed.
* This function reads the current state of the parameters.
**/
is_private(entry : Api.entry) =
params = OpaDocParameters.get()
if params.private
then false
else
match entry.code_elt with
| { type_def = { ty_def_visibility = { TDV_private = _ } ; ... } } -> true
| { type_def = _ } -> false
| { value = { visibility = { public }; ... } } -> false
| { value = _ } -> true
/**
* Tell if an entry is a type_def
**/
entry_is_type_def(entry:Api.entry) =
match entry.code_elt with
| { type_def = _ } -> true
| _ -> false
/**
* Tell if an entry is a type_def
**/
entry_is_value(entry:Api.entry) =
match entry.code_elt with
| { value = _ } -> true
| _ -> false
/**
* Sort using a string in the fst
**/
sort_by_string(list) =
aux((p1, _), (p2, _)) =
String.ordering(String.to_lower(p1), String.to_lower(p2))
List.sort_with(aux, list)
uri_of_path =
if OpaDocParameters.get().long_uris
then String.replace(File.dir_sep, ".", _)
else File.basename
}}