a partial solution for issue #73: ldoc.module_file to pick master modules when present
Steve Donovan
10 years ago
176 | 176 | return this_mod and this_mod.section and this_mod.section.type |
177 | 177 | end |
178 | 178 | |
179 | local function find_module_in_files (name) | |
179 | function File:find_module_in_files (name) | |
180 | 180 | for f in File.list:iter() do |
181 | 181 | for m in f.modules:iter() do |
182 | 182 | if m.name == name then |
215 | 215 | -- if name is 'package.mod', then mod_name is 'mod' |
216 | 216 | package,mname = split_dotted_name(this_mod.name) |
217 | 217 | if self.args.merge then |
218 | local mod,mf = find_module_in_files(item.name) | |
218 | local mod,mf = self:find_module_in_files(item.name) | |
219 | 219 | if mod then |
220 | 220 | print('found master module',mf) |
221 | 221 | this_mod = mod |
229 | 229 | elseif item.type == 'submodule' then |
230 | 230 | local mf |
231 | 231 | submodule = true |
232 | this_mod,mf = find_module_in_files(item.name) | |
232 | this_mod,mf = self:find_module_in_files(item.name) | |
233 | 233 | if this_mod == nil then |
234 | 234 | self:error("'"..item.name.."' not found for submodule") |
235 | 235 | end |
210 | 210 | ldoc.pairs = pairs |
211 | 211 | ldoc.print = print |
212 | 212 | |
213 | -- Bang out the index. | |
213 | 214 | -- in single mode there is one module and the 'index' is the |
214 | 215 | -- documentation for that module. |
215 | 216 | ldoc.module = ldoc.single |
236 | 237 | |
237 | 238 | args.dir = args.dir .. path.sep |
238 | 239 | |
239 | check_file(args.dir..css, path.join(args.style,css)) -- has CSS been copied? | |
240 | if ldoc.css then -- has CSS been copied? | |
241 | check_file(args.dir..css, path.join(args.style,css)) | |
242 | end | |
240 | 243 | |
241 | 244 | -- write out the module index |
242 | 245 | out = cleanup_whitespaces(out) |
243 | 246 | writefile(args.dir..args.output..args.ext,out) |
244 | 247 | |
245 | 248 | -- in single mode, we exclude any modules since the module has been done; |
246 | -- this step is then only for putting out any examples or topics | |
249 | -- ext step is then only for putting out any examples or topics | |
247 | 250 | local mods = List() |
248 | 251 | for kind, modules in project() do |
249 | 252 | local lkind = kind:lower() |
17 | 17 | |
18 | 18 | -- this constructs an iterator over a list of objects which returns only |
19 | 19 | -- those objects where a field has a certain value. It's used to iterate |
20 | -- only over functions or tables, etc. | |
20 | -- only over functions or tables, etc. If the list of item has a module | |
21 | -- with a context, then use that to pre-sort the fltered items. | |
21 | 22 | -- (something rather similar exists in LuaDoc) |
22 | 23 | function M.type_iterator (list,field,value) |
23 | 24 | return function() |
24 | local i, fls = 1, {} | |
25 | for j = 1,#list do | |
26 | local val = list[j] | |
27 | if val[field] == value then | |
28 | fls[i] = val | |
29 | i = i + 1 | |
30 | end | |
31 | end | |
32 | i = 0 | |
33 | local mod = fls[1].module | |
25 | local fls = list:filter(function(item) | |
26 | return item[field] == value | |
27 | end) | |
28 | local mod = fls[1] and fls[1].module | |
34 | 29 | local ldoc = mod and mod.ldoc |
35 | 30 | if ldoc and ldoc.sort then |
36 | table.sort(fls,function(ia,ib) | |
31 | fls:sort(function(ia,ib) | |
37 | 32 | return ia.name < ib.name |
38 | 33 | end) |
39 | 34 | end |
40 | return function() | |
41 | i = i + 1 | |
42 | local val = fls[i] | |
43 | if val ~= nil then return val end | |
44 | end | |
35 | return fls:iter() | |
45 | 36 | end |
46 | 37 | end |
47 | 38 |
185 | 185 | 'alias','add_language_extension','new_type','add_section', 'tparam_alias', |
186 | 186 | 'file','project','title','package','format','output','dir','ext', 'topics', |
187 | 187 | 'one','style','template','description','examples', 'pretty', 'charset', 'plain', |
188 | 'readme','all','manual_url', 'ignore', 'colon', 'sort', | |
188 | 'readme','all','manual_url', 'ignore', 'colon', 'sort', 'module_file', | |
189 | 189 | 'boilerplate','merge', 'wrap', 'not_luadoc', |
190 | 190 | 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler', |
191 | 191 | } |
260 | 260 | end |
261 | 261 | end |
262 | 262 | |
263 | local function fixup_module_file (file, fullpath) | |
264 | if args.module_file then | |
265 | for mname, f in pairs(args.module_file) do | |
266 | if f == file then | |
267 | args.module_file[mname] = fullpath | |
268 | args.module_file[fullpath] = true | |
269 | return "master for "..mname | |
270 | end | |
271 | end | |
272 | end | |
273 | return '' | |
274 | end | |
275 | ||
276 | -- partial sort of file list, where anything in module_file is now upfront! | |
277 | local function reorder_module_file (files) | |
278 | if args.module_file then | |
279 | local mf = args.module_file | |
280 | table.sort(files,function(x,y) return mf[x] and not mf[y] end) | |
281 | end | |
282 | end | |
283 | ||
263 | 284 | local abspath = tools.abspath |
264 | 285 | |
265 | 286 | -- a special case: 'ldoc .' can get all its parameters from config.ld |
273 | 294 | lfs.chdir(config_path) |
274 | 295 | end |
275 | 296 | config_is_read = true |
297 | override 'module_file' | |
276 | 298 | args.file = ldoc.file or '.' |
277 | 299 | if args.file == '.' then |
278 | 300 | args.file = lfs.currentdir() |
279 | 301 | elseif type(args.file) == 'table' then |
280 | 302 | for i,f in ipairs(args.file) do |
281 | 303 | args.file[i] = abspath(f) |
282 | print(args.file[i]) | |
283 | end | |
304 | fixup_module_file(f,args.file[i]) | |
305 | end | |
306 | reorder_module_file(args.file) | |
284 | 307 | else |
285 | 308 | args.file = abspath(args.file) |
286 | 309 | end |
344 | 367 | local ext = path.extension(f) |
345 | 368 | local ftype = file_types[ext] |
346 | 369 | if ftype then |
347 | if args.verbose then print(path.basename(f)) end | |
370 | if args.verbose then print(f) end | |
348 | 371 | local F,err = parse.file(f,ftype,args) |
349 | 372 | if err then |
350 | 373 | if F then |