issue #64: use 'sort=true' in config.ld to sort items in sections

This commit is contained in:
Steve Donovan 2013-07-31 14:25:33 +02:00
parent eb00a499b2
commit 8a071fb517
3 changed files with 35 additions and 14 deletions

View File

@ -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',
'readme','all','manual_url', 'ignore', 'colon', 'sort',
'boilerplate','merge', 'wrap', 'not_luadoc',
'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
}

View File

@ -58,10 +58,21 @@ function html.generate_output(ldoc, args, project)
local check_directory, check_file, writefile = tools.check_directory, tools.check_file, tools.writefile
local original_ldoc
local function save_ldoc ()
local function save_and_set_ldoc (set)
if not set then return end
if not original_ldoc then
original_ldoc = tablex.copy(ldoc)
end
for s in set:iter() do
local var,val = s:match('([^=]+)=(.+)')
local num = tonumber(val)
if num then val = num
elseif val == 'true' then val = true
elseif val == 'false' then val = false
end
print('setting',var,val)
ldoc[var] = val
end
end
local function restore_ldoc ()
@ -210,6 +221,8 @@ function html.generate_output(ldoc, args, project)
ldoc.root = true
if ldoc.module then
ldoc.module.info = get_module_info(ldoc.module)
ldoc.module.ldoc = ldoc
save_and_set_ldoc(ldoc.module.tags.set)
end
set_charset(ldoc)
local out,err = template.substitute(module_template,{
@ -218,6 +231,7 @@ function html.generate_output(ldoc, args, project)
})
ldoc.root = false
if not out then quit("template failed: "..err) end
restore_ldoc()
check_directory(args.dir) -- make sure output directory is ok
@ -250,13 +264,9 @@ function html.generate_output(ldoc, args, project)
for m in modules() do
ldoc.module = m
ldoc.body = m.body
m.ldoc = ldoc
if m.tags.set then
save_ldoc()
for s in m.tags.set:iter() do
local var,val = s:match('([^=]+)=(.+)')
print('setting',var,val)
ldoc[var] = val
end
save_and_set_ldoc(m.tags.set)
end
set_charset(ldoc)
m.info = get_module_info(m)

View File

@ -22,15 +22,26 @@ local lfs = require 'lfs'
-- (something rather similar exists in LuaDoc)
function M.type_iterator (list,field,value)
return function()
local i = 1
return function()
local val = list[i]
while val and val[field] ~= value do
local i, fls = 1, {}
for j = 1,#list do
local val = list[j]
if val[field] == value then
fls[i] = val
i = i + 1
val = list[i]
end
end
i = 0
local mod = fls[1].module
local ldoc = mod and mod.ldoc
if ldoc and ldoc.sort then
table.sort(fls,function(ia,ib)
return ia.name < ib.name
end)
end
return function()
i = i + 1
if val then return val end
local val = fls[i]
if val ~= nil then return val end
end
end
end