diff --git a/ldoc.lua b/ldoc.lua index ec53453..b402810 100644 --- a/ldoc.lua +++ b/ldoc.lua @@ -186,7 +186,7 @@ local ldoc_contents = { 'alias','add_language_extension','new_type','add_section', 'tparam_alias', 'file','project','title','package','format','output','dir','ext', 'topics', 'one','style','template','description','examples', 'pretty', 'charset', 'plain', - 'readme','all','manual_url', 'ignore', 'colon', 'sort', + 'readme','all','manual_url', 'ignore', 'colon', 'sort', 'module_file', 'boilerplate','merge', 'wrap', 'not_luadoc', 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler', } @@ -261,6 +261,27 @@ if args.module then end end +local function fixup_module_file (file, fullpath) + if args.module_file then + for mname, f in pairs(args.module_file) do + if f == file then + args.module_file[mname] = fullpath + args.module_file[fullpath] = true + return "master for "..mname + end + end + end + return '' +end + +-- partial sort of file list, where anything in module_file is now upfront! +local function reorder_module_file (files) + if args.module_file then + local mf = args.module_file + table.sort(files,function(x,y) return mf[x] and not mf[y] end) + end +end + local abspath = tools.abspath -- a special case: 'ldoc .' can get all its parameters from config.ld @@ -274,14 +295,16 @@ if args.file == '.' then lfs.chdir(config_path) end config_is_read = true + override 'module_file' args.file = ldoc.file or '.' if args.file == '.' then args.file = lfs.currentdir() elseif type(args.file) == 'table' then for i,f in ipairs(args.file) do args.file[i] = abspath(f) - print(args.file[i]) + fixup_module_file(f,args.file[i]) end + reorder_module_file(args.file) else args.file = abspath(args.file) end @@ -345,7 +368,7 @@ local function process_file (f, flist) local ext = path.extension(f) local ftype = file_types[ext] if ftype then - if args.verbose then print(path.basename(f)) end + if args.verbose then print(f) end local F,err = parse.file(f,ftype,args) if err then if F then diff --git a/ldoc/doc.lua b/ldoc/doc.lua index f1fac61..f97672d 100644 --- a/ldoc/doc.lua +++ b/ldoc/doc.lua @@ -177,7 +177,7 @@ local function mod_section_type (this_mod) return this_mod and this_mod.section and this_mod.section.type end -local function find_module_in_files (name) +function File:find_module_in_files (name) for f in File.list:iter() do for m in f.modules:iter() do if m.name == name then @@ -216,7 +216,7 @@ function File:finish() -- if name is 'package.mod', then mod_name is 'mod' package,mname = split_dotted_name(this_mod.name) if self.args.merge then - local mod,mf = find_module_in_files(item.name) + local mod,mf = self:find_module_in_files(item.name) if mod then print('found master module',mf) this_mod = mod @@ -230,7 +230,7 @@ function File:finish() elseif item.type == 'submodule' then local mf submodule = true - this_mod,mf = find_module_in_files(item.name) + this_mod,mf = self:find_module_in_files(item.name) if this_mod == nil then self:error("'"..item.name.."' not found for submodule") end diff --git a/ldoc/html.lua b/ldoc/html.lua index c224a88..c940665 100644 --- a/ldoc/html.lua +++ b/ldoc/html.lua @@ -211,6 +211,7 @@ function html.generate_output(ldoc, args, project) ldoc.pairs = pairs ldoc.print = print + -- Bang out the index. -- in single mode there is one module and the 'index' is the -- documentation for that module. ldoc.module = ldoc.single @@ -237,14 +238,16 @@ function html.generate_output(ldoc, args, project) args.dir = args.dir .. path.sep - check_file(args.dir..css, path.join(args.style,css)) -- has CSS been copied? + if ldoc.css then -- has CSS been copied? + check_file(args.dir..css, path.join(args.style,css)) + end -- write out the module index out = cleanup_whitespaces(out) writefile(args.dir..args.output..args.ext,out) -- in single mode, we exclude any modules since the module has been done; - -- this step is then only for putting out any examples or topics + -- ext step is then only for putting out any examples or topics local mods = List() for kind, modules in project() do local lkind = kind:lower() diff --git a/ldoc/tools.lua b/ldoc/tools.lua index 22f34a2..bb5c5f1 100644 --- a/ldoc/tools.lua +++ b/ldoc/tools.lua @@ -18,31 +18,22 @@ local lfs = require 'lfs' -- this constructs an iterator over a list of objects which returns only -- those objects where a field has a certain value. It's used to iterate --- only over functions or tables, etc. +-- only over functions or tables, etc. If the list of item has a module +-- with a context, then use that to pre-sort the fltered items. -- (something rather similar exists in LuaDoc) function M.type_iterator (list,field,value) return function() - local i, fls = 1, {} - for j = 1,#list do - local val = list[j] - if val[field] == value then - fls[i] = val - i = i + 1 - end - end - i = 0 - local mod = fls[1].module + local fls = list:filter(function(item) + return item[field] == value + end) + local mod = fls[1] and fls[1].module local ldoc = mod and mod.ldoc if ldoc and ldoc.sort then - table.sort(fls,function(ia,ib) + fls:sort(function(ia,ib) return ia.name < ib.name end) end - return function() - i = i + 1 - local val = fls[i] - if val ~= nil then return val end - end + return fls:iter() end end