a partial solution for issue #73: ldoc.module_file to pick master modules when present

This commit is contained in:
Steve Donovan 2013-08-01 12:14:57 +02:00
parent 8a071fb517
commit 7fe6a95544
4 changed files with 42 additions and 25 deletions

View File

@ -186,7 +186,7 @@ local ldoc_contents = {
'alias','add_language_extension','new_type','add_section', 'tparam_alias', 'alias','add_language_extension','new_type','add_section', 'tparam_alias',
'file','project','title','package','format','output','dir','ext', 'topics', 'file','project','title','package','format','output','dir','ext', 'topics',
'one','style','template','description','examples', 'pretty', 'charset', 'plain', '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', 'boilerplate','merge', 'wrap', 'not_luadoc',
'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler', 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
} }
@ -261,6 +261,27 @@ if args.module then
end end
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 local abspath = tools.abspath
-- a special case: 'ldoc .' can get all its parameters from config.ld -- a special case: 'ldoc .' can get all its parameters from config.ld
@ -274,14 +295,16 @@ if args.file == '.' then
lfs.chdir(config_path) lfs.chdir(config_path)
end end
config_is_read = true config_is_read = true
override 'module_file'
args.file = ldoc.file or '.' args.file = ldoc.file or '.'
if args.file == '.' then if args.file == '.' then
args.file = lfs.currentdir() args.file = lfs.currentdir()
elseif type(args.file) == 'table' then elseif type(args.file) == 'table' then
for i,f in ipairs(args.file) do for i,f in ipairs(args.file) do
args.file[i] = abspath(f) args.file[i] = abspath(f)
print(args.file[i]) fixup_module_file(f,args.file[i])
end end
reorder_module_file(args.file)
else else
args.file = abspath(args.file) args.file = abspath(args.file)
end end
@ -345,7 +368,7 @@ local function process_file (f, flist)
local ext = path.extension(f) local ext = path.extension(f)
local ftype = file_types[ext] local ftype = file_types[ext]
if ftype then 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) local F,err = parse.file(f,ftype,args)
if err then if err then
if F then if F then

View File

@ -177,7 +177,7 @@ local function mod_section_type (this_mod)
return this_mod and this_mod.section and this_mod.section.type return this_mod and this_mod.section and this_mod.section.type
end end
local function find_module_in_files (name) function File:find_module_in_files (name)
for f in File.list:iter() do for f in File.list:iter() do
for m in f.modules:iter() do for m in f.modules:iter() do
if m.name == name then if m.name == name then
@ -216,7 +216,7 @@ function File:finish()
-- if name is 'package.mod', then mod_name is 'mod' -- if name is 'package.mod', then mod_name is 'mod'
package,mname = split_dotted_name(this_mod.name) package,mname = split_dotted_name(this_mod.name)
if self.args.merge then 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 if mod then
print('found master module',mf) print('found master module',mf)
this_mod = mod this_mod = mod
@ -230,7 +230,7 @@ function File:finish()
elseif item.type == 'submodule' then elseif item.type == 'submodule' then
local mf local mf
submodule = true 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 if this_mod == nil then
self:error("'"..item.name.."' not found for submodule") self:error("'"..item.name.."' not found for submodule")
end end

View File

@ -211,6 +211,7 @@ function html.generate_output(ldoc, args, project)
ldoc.pairs = pairs ldoc.pairs = pairs
ldoc.print = print ldoc.print = print
-- Bang out the index.
-- in single mode there is one module and the 'index' is the -- in single mode there is one module and the 'index' is the
-- documentation for that module. -- documentation for that module.
ldoc.module = ldoc.single ldoc.module = ldoc.single
@ -237,14 +238,16 @@ function html.generate_output(ldoc, args, project)
args.dir = args.dir .. path.sep 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 -- write out the module index
out = cleanup_whitespaces(out) out = cleanup_whitespaces(out)
writefile(args.dir..args.output..args.ext,out) writefile(args.dir..args.output..args.ext,out)
-- in single mode, we exclude any modules since the module has been done; -- 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() local mods = List()
for kind, modules in project() do for kind, modules in project() do
local lkind = kind:lower() local lkind = kind:lower()

View File

@ -18,31 +18,22 @@ local lfs = require 'lfs'
-- this constructs an iterator over a list of objects which returns only -- 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 -- 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) -- (something rather similar exists in LuaDoc)
function M.type_iterator (list,field,value) function M.type_iterator (list,field,value)
return function() return function()
local i, fls = 1, {} local fls = list:filter(function(item)
for j = 1,#list do return item[field] == value
local val = list[j] end)
if val[field] == value then local mod = fls[1] and fls[1].module
fls[i] = val
i = i + 1
end
end
i = 0
local mod = fls[1].module
local ldoc = mod and mod.ldoc local ldoc = mod and mod.ldoc
if ldoc and ldoc.sort then if ldoc and ldoc.sort then
table.sort(fls,function(ia,ib) fls:sort(function(ia,ib)
return ia.name < ib.name return ia.name < ib.name
end) end)
end end
return function() return fls:iter()
i = i + 1
local val = fls[i]
if val ~= nil then return val end
end
end end
end end