@type summary no longer dropped (#49); @type can be used with @usage (#52); CSS tweaks for prettification; nasty '<pre/>' typo squashed
steve donovan
11 years ago
193 | 193 |
local function add_section (item, display_name)
|
194 | 194 |
display_name = display_name or item.display_name
|
195 | 195 |
this_mod.section = item
|
196 | |
this_mod.kinds:add_kind(display_name,display_name)
|
|
196 |
this_mod.kinds:add_kind(display_name,display_name,nil,item)
|
197 | 197 |
this_mod.sections:append(item)
|
198 | 198 |
this_mod.sections.by_name[display_name:gsub('%A','_')] = item
|
199 | 199 |
end
|
|
313 | 313 |
end
|
314 | 314 |
end
|
315 | 315 |
end
|
316 | |
section_description = this_section.description
|
|
316 |
section_description = this_section.summary..' '..this_section.description
|
317 | 317 |
elseif item.tags.within then
|
318 | 318 |
section_description = item.tags.within
|
319 | 319 |
item.section = section_description
|
282 | 282 |
ul ol { margin-top: 0px; }
|
283 | 283 |
|
284 | 284 |
/* styles for prettification of source */
|
285 | |
/*
|
286 | |
.keyword {font-weight: bold; color: #6666AA; }
|
287 | |
.number { color: #AA6666; }
|
288 | |
.string { color: #8888AA; }
|
289 | |
.comment { color: #666600; }
|
290 | |
.prepro { color: #006666; }
|
291 | |
.global { color: #800080; }
|
292 | |
*/
|
293 | 285 |
pre .comment { color: #558817; }
|
294 | 286 |
pre .constant { color: #a8660d; }
|
295 | 287 |
pre .escape { color: #844631; }
|
|
297 | 289 |
pre .library { color: #0e7c6b; }
|
298 | 290 |
pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; }
|
299 | 291 |
pre .string { color: #a8660d; }
|
300 | |
pre .number { color: #a8660d; }
|
|
292 |
pre .number { color: #f8660d; }
|
301 | 293 |
pre .operator { color: #2239a8; font-weight: bold; }
|
302 | 294 |
pre .preprocessor, pre .prepro { color: #a33243; }
|
|
295 |
pre .global { color: #800080; }
|
303 | 296 |
pre .prompt { color: #558817; }
|
304 | 297 |
pre .url { color: #272fc2; text-decoration: underline; }
|
305 | 298 |
]==]
|
134 | 134 |
# local show_return = not ldoc.no_return_or_parms
|
135 | 135 |
# local show_parms = show_return
|
136 | 136 |
# for kind, items in module.kinds() do
|
|
137 |
# local kitem = module.kinds:get_item(kind)
|
137 | 138 |
<h2><a name="$(no_spaces(kind))"></a>$(kind)</h2>
|
138 | |
$(M(module.kinds:get_section_description(kind),nil))
|
|
139 |
#-- $(M(module.kinds:get_section_description(kind),nil))
|
|
140 |
# if kitem then
|
|
141 |
$(M(ldoc.descript(kitem),kitem))
|
|
142 |
# if kitem.usage then
|
|
143 |
<h3>Usage:</h3>
|
|
144 |
<pre class="example">$(ldoc.prettify(kitem.usage[1]))</pre>
|
|
145 |
# end
|
|
146 |
# end
|
139 | 147 |
<dl class="function">
|
140 | 148 |
# for item in items() do
|
141 | 149 |
<dt>
|
|
143 | 151 |
<strong>$(display_name(item))</strong>
|
144 | 152 |
</dt>
|
145 | 153 |
<dd>
|
146 | |
$(M((item.summary or '?')..' '..(item.description or ''),item))
|
|
154 |
$(M(ldoc.descript(item),item))
|
147 | 155 |
|
148 | 156 |
# if show_parms and item.params and #item.params > 0 then
|
149 | 157 |
<h3>$(module.kinds:type_of(item).subnames):</h3>
|
61 | 61 |
|
62 | 62 |
function ldoc.prettify(str)
|
63 | 63 |
return prettify.code('lua','usage',str,0,false)
|
|
64 |
end
|
|
65 |
|
|
66 |
-- Item descriptions come from combining the summary and description fields
|
|
67 |
function ldoc.descript(item)
|
|
68 |
return (item.summary or '?')..' '..(item.description or '')
|
64 | 69 |
end
|
65 | 70 |
|
66 | 71 |
-- this generates the internal module/function references
|
60 | 60 |
res[#res] = last:gsub('\n+','')
|
61 | 61 |
end
|
62 | 62 |
if pre then
|
63 | |
res:append '<pre/>\n'
|
|
63 |
res:append '</pre>\n'
|
64 | 64 |
end
|
65 | 65 |
return res:join ()
|
66 | 66 |
end
|
89 | 89 |
return self.klass.descriptions[kind]
|
90 | 90 |
end
|
91 | 91 |
|
|
92 |
function KindMap:get_item (kind)
|
|
93 |
return self.klass.items_by_kind[kind]
|
|
94 |
end
|
|
95 |
|
92 | 96 |
-- called for each new item. It does not actually create separate lists,
|
93 | 97 |
-- (although that would not break the interface) but creates iterators
|
94 | 98 |
-- for that item type if not already created.
|
|
109 | 113 |
klass.types_by_tag = {} -- indexed by tag
|
110 | 114 |
klass.types_by_kind = {} -- indexed by kind
|
111 | 115 |
klass.descriptions = {} -- optional description for each kind
|
112 | |
end
|
113 | |
|
114 | |
|
115 | |
function KindMap.add_kind (klass,tag,kind,subnames)
|
|
116 |
klass.items_by_kind = {} -- some kinds are items
|
|
117 |
end
|
|
118 |
|
|
119 |
|
|
120 |
function KindMap.add_kind (klass,tag,kind,subnames,item)
|
116 | 121 |
if not klass.types_by_kind[kind] then
|
117 | 122 |
klass.types_by_tag[tag] = kind
|
118 | 123 |
klass.types_by_kind[kind] = {type=tag,subnames=subnames}
|
|
124 |
if item then
|
|
125 |
klass.items_by_kind[kind] = item
|
|
126 |
end
|
119 | 127 |
append(klass.kinds,kind)
|
120 | 128 |
end
|
121 | 129 |
end
|
0 | 0 |
project = 'usage'
|
1 | 1 |
file = 'usage.lua'
|
|
2 |
examples='usage.lua'
|
|
3 |
-- can specify both the Markdown processor
|
|
4 |
-- and the prettifier - this will use lxsh if available
|
2 | 5 |
format='markdown'
|
|
6 |
pretty='lxsh'
|
|
7 |
-- suppress @params and the summary at the top
|
3 | 8 |
no_return_or_parms=true
|
4 | 9 |
no_summary=true
|
6 | 6 |
local usage = {}
|
7 | 7 |
|
8 | 8 |
----------
|
9 | |
-- A simple vector class
|
|
9 |
-- A simple vector class.
|
|
10 |
--
|
|
11 |
-- Supports arithmetic operations.
|
|
12 |
-- @usage
|
|
13 |
-- v = Vector.new {10,20,30}
|
|
14 |
-- assert (v == Vector{10,20,30})
|
10 | 15 |
-- @type Vector
|
11 | 16 |
|
12 | 17 |
local Vector = {}
|
|
14 | 19 |
|
15 | 20 |
----------
|
16 | 21 |
-- Create a vector from an array `t`.
|
|
22 |
-- `Vector` is also callable!
|
17 | 23 |
function Vector.new (t)
|
18 | 24 |
end
|
19 | 25 |
|
|
23 | 29 |
-- v = Vector.parse '[1,2,3]'
|
24 | 30 |
-- assert (v == Vector.new {1,2,3})
|
25 | 31 |
function Vector.parse (s)
|
|
32 |
end
|
|
33 |
|
|
34 |
--------
|
|
35 |
-- Compare two vectors for equality.
|
|
36 |
function Vector:__eq (v)
|
26 | 37 |
end
|
27 | 38 |
|
28 | 39 |
----------
|