Codebase list lua-ldoc / 496b534
@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
8 changed file(s) with 49 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
193193 local function add_section (item, display_name)
194194 display_name = display_name or item.display_name
195195 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)
197197 this_mod.sections:append(item)
198198 this_mod.sections.by_name[display_name:gsub('%A','_')] = item
199199 end
313313 end
314314 end
315315 end
316 section_description = this_section.description
316 section_description = this_section.summary..' '..this_section.description
317317 elseif item.tags.within then
318318 section_description = item.tags.within
319319 item.section = section_description
282282 ul ol { margin-top: 0px; }
283283
284284 /* 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 */
293285 pre .comment { color: #558817; }
294286 pre .constant { color: #a8660d; }
295287 pre .escape { color: #844631; }
297289 pre .library { color: #0e7c6b; }
298290 pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; }
299291 pre .string { color: #a8660d; }
300 pre .number { color: #a8660d; }
292 pre .number { color: #f8660d; }
301293 pre .operator { color: #2239a8; font-weight: bold; }
302294 pre .preprocessor, pre .prepro { color: #a33243; }
295 pre .global { color: #800080; }
303296 pre .prompt { color: #558817; }
304297 pre .url { color: #272fc2; text-decoration: underline; }
305298 ]==]
134134 # local show_return = not ldoc.no_return_or_parms
135135 # local show_parms = show_return
136136 # for kind, items in module.kinds() do
137 # local kitem = module.kinds:get_item(kind)
137138 <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
139147 <dl class="function">
140148 # for item in items() do
141149 <dt>
143151 <strong>$(display_name(item))</strong>
144152 </dt>
145153 <dd>
146 $(M((item.summary or '?')..' '..(item.description or ''),item))
154 $(M(ldoc.descript(item),item))
147155
148156 # if show_parms and item.params and #item.params > 0 then
149157 <h3>$(module.kinds:type_of(item).subnames):</h3>
6161
6262 function ldoc.prettify(str)
6363 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 '')
6469 end
6570
6671 -- this generates the internal module/function references
6060 res[#res] = last:gsub('\n+','')
6161 end
6262 if pre then
63 res:append '<pre/>\n'
63 res:append '</pre>\n'
6464 end
6565 return res:join ()
6666 end
8989 return self.klass.descriptions[kind]
9090 end
9191
92 function KindMap:get_item (kind)
93 return self.klass.items_by_kind[kind]
94 end
95
9296 -- called for each new item. It does not actually create separate lists,
9397 -- (although that would not break the interface) but creates iterators
9498 -- for that item type if not already created.
109113 klass.types_by_tag = {} -- indexed by tag
110114 klass.types_by_kind = {} -- indexed by kind
111115 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)
116121 if not klass.types_by_kind[kind] then
117122 klass.types_by_tag[tag] = kind
118123 klass.types_by_kind[kind] = {type=tag,subnames=subnames}
124 if item then
125 klass.items_by_kind[kind] = item
126 end
119127 append(klass.kinds,kind)
120128 end
121129 end
00 project = 'usage'
11 file = 'usage.lua'
2 examples='usage.lua'
3 -- can specify both the Markdown processor
4 -- and the prettifier - this will use lxsh if available
25 format='markdown'
6 pretty='lxsh'
7 -- suppress @params and the summary at the top
38 no_return_or_parms=true
49 no_summary=true
66 local usage = {}
77
88 ----------
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})
1015 -- @type Vector
1116
1217 local Vector = {}
1419
1520 ----------
1621 -- Create a vector from an array `t`.
22 -- `Vector` is also callable!
1723 function Vector.new (t)
1824 end
1925
2329 -- v = Vector.parse '[1,2,3]'
2430 -- assert (v == Vector.new {1,2,3})
2531 function Vector.parse (s)
32 end
33
34 --------
35 -- Compare two vectors for equality.
36 function Vector:__eq (v)
2637 end
2738
2839 ----------