forked from BigWigsMods/BigWigs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldoc.ltp
134 lines (115 loc) · 3.72 KB
/
ldoc.ltp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
> local function format_anchor_link(name)
> -- make an educated guess at what the id of the function header will be
> return name:lower():gsub("%p", ""):gsub("%s", "-")
> end
> local function format_see_link(see)
> if see.href then return see.href end
> return format_anchor_link(see.name)
> end
> local function trim(s) return s:match('^%s*(.*%S)') or '' end
> local escape = ldoc.escape
> local show_return_and_params = not ldoc.no_return_or_parms
> local num_kinds = 0 for _ in module.kinds() do num_kinds = num_kinds + 1 end
> --# $(module.name)
# $(escape(module.summary))
$(escape(module.description))
>
> if module.usage then
### Usage:
> for usage in ldoc.modules.iter(module.usage) do
```lua
$(usage)
```
> end -- for
> end -- if usage
> if module.info then -- copyright, author, license, release
> for tag, value in module.info:iter() do
- **$(tag)**: $(escape(value))
> end
> end -- if module.info
> -- for simple show a list of kinds, otherwise show tables of items for a kind
> -- we use html tables for colspan on the header (width is overrided by display:block on github :\)
> -- and a headerless table for the "simple" list
> if not ldoc.no_summary then
> for kind, items in module.kinds() do
<table width="100%">
<tr>
<th colspan="2" align="left">$(trim(kind))</th>
</tr>
> for item in items() do
> local name = ldoc.display_name(item)
> local summary = ldoc.markup(item.summary, item, 'discount') -- inline html and md don't mix, so render out the html (to get stripped away later, probably)
<tr>
<td><a href="#$(format_anchor_link(name))">$(name)</a></td>
<td>$(summary)</td>
</tr>
> end -- for items
</table>
> end -- for kinds
> elseif num_kinds > 0 then
<table>
> for kind in module.kinds() do
<tr>
<td><a href="#$(format_anchor_link(kind))">$(kind)</a></td>
</tr>
> end
</table>
> end -- if show_summary
> for kind, items in module.kinds() do
# $(kind)
> for item in items() do
### $(ldoc.display_name(item))
$(escape(ldoc.descript(item)))
> if show_return_and_params and item.params and #item.params > 0 then
> local subnames = module.kinds:type_of(item).subnames
> if subnames then
**$(subnames):**
> end
> for parm in ldoc.modules.iter(item.params) do
> local param, sublist = item:subparam(parm)
> for p in ldoc.modules.iter(param) do
> local name, tp = item:display_name_of(p), item:type_of_param(p)
> local desc = escape(item.params.map[p])
> if tp ~= "" then desc = "["..tp.."] "..desc end
> local def = item:default_of_param(p)
> if def == true then desc = desc.." (_optional_)"
> elseif def then desc = desc.." (*default*: "..def..")" end
> if desc ~= "" then
- `$(name)`: $(desc)
> else
- `$(name)`
> end
> end -- for p
> end -- for parm
> end -- if params
> if show_return_and_params and item.retgroups then
**Returns:**
> for _, group in ldoc.ipairs(item.retgroups) do
> for r in group:iter() do
> local type, ctypes = item:return_type(r)
> local rt = ldoc.typename(type)
- $(rt) $(escape(r.text))
> end -- for r
> end -- for _
> end -- if returns
>
> if item.see then
**See also:**
> for see in ldoc.modules.iter(item.see) do
> -- can't get the full fucking function definition! so the link doesn't work with functions with args
- [$(see.label)](#$(format_see_link(see)))
> end -- for
> end -- if see
>
> if item.usage then
**Usage:**
> for usage in ldoc.modules.iter(item.usage) do
> usage = usage:gsub("\n ", "\n") -- strip leading space (adjusting for "-- [code]")
```lua
$(usage)
```
> end
> end
---
> end -- for item
> end -- for kind