Codebase list lua-ldoc / 7fe6a95
a partial solution for issue #73: ldoc.module_file to pick master modules when present Steve Donovan 10 years ago
4 changed file(s) with 43 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
176176 return this_mod and this_mod.section and this_mod.section.type
177177 end
178178
179 local function find_module_in_files (name)
179 function File:find_module_in_files (name)
180180 for f in File.list:iter() do
181181 for m in f.modules:iter() do
182182 if m.name == name then
215215 -- if name is 'package.mod', then mod_name is 'mod'
216216 package,mname = split_dotted_name(this_mod.name)
217217 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)
219219 if mod then
220220 print('found master module',mf)
221221 this_mod = mod
229229 elseif item.type == 'submodule' then
230230 local mf
231231 submodule = true
232 this_mod,mf = find_module_in_files(item.name)
232 this_mod,mf = self:find_module_in_files(item.name)
233233 if this_mod == nil then
234234 self:error("'"..item.name.."' not found for submodule")
235235 end
210210 ldoc.pairs = pairs
211211 ldoc.print = print
212212
213 -- Bang out the index.
213214 -- in single mode there is one module and the 'index' is the
214215 -- documentation for that module.
215216 ldoc.module = ldoc.single
236237
237238 args.dir = args.dir .. path.sep
238239
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
240243
241244 -- write out the module index
242245 out = cleanup_whitespaces(out)
243246 writefile(args.dir..args.output..args.ext,out)
244247
245248 -- 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
247250 local mods = List()
248251 for kind, modules in project() do
249252 local lkind = kind:lower()
1717
1818 -- this constructs an iterator over a list of objects which returns only
1919 -- 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.
2122 -- (something rather similar exists in LuaDoc)
2223 function M.type_iterator (list,field,value)
2324 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
3429 local ldoc = mod and mod.ldoc
3530 if ldoc and ldoc.sort then
36 table.sort(fls,function(ia,ib)
31 fls:sort(function(ia,ib)
3732 return ia.name < ib.name
3833 end)
3934 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()
4536 end
4637 end
4738
185185 'alias','add_language_extension','new_type','add_section', 'tparam_alias',
186186 'file','project','title','package','format','output','dir','ext', 'topics',
187187 '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',
189189 'boilerplate','merge', 'wrap', 'not_luadoc',
190190 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
191191 }
260260 end
261261 end
262262
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
263284 local abspath = tools.abspath
264285
265286 -- a special case: 'ldoc .' can get all its parameters from config.ld
273294 lfs.chdir(config_path)
274295 end
275296 config_is_read = true
297 override 'module_file'
276298 args.file = ldoc.file or '.'
277299 if args.file == '.' then
278300 args.file = lfs.currentdir()
279301 elseif type(args.file) == 'table' then
280302 for i,f in ipairs(args.file) do
281303 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)
284307 else
285308 args.file = abspath(args.file)
286309 end
344367 local ext = path.extension(f)
345368 local ftype = file_types[ext]
346369 if ftype then
347 if args.verbose then print(path.basename(f)) end
370 if args.verbose then print(f) end
348371 local F,err = parse.file(f,ftype,args)
349372 if err then
350373 if F then