local discount = function(s) return (require 'discount')(s, "nopants") end
local actions = {}
local function filter(t, p)
local r = {}
for _,v in ipairs(t) do
if p(v) then r[#r+1] = v end
end
return r
end
-- generic
function actions.textblock(info)
return discount(info[1])
end
function actions.section(info)
local htype = 'h'..(info[3]+1)
if info[3] >= 3 then
return table.concat{
'
'
}
end
-- function
function actions.parameters(info)
return discount(info[1]):gsub('
([^<]+)
', function(m)
local type, what, optional = m:match("(%S+) ([^%(]+)( %b())")
if not type then
optional, type, what = '', m:match("(%S+) ([^%(]+)%s*")
end
assert(type and what and optional, "Invalid parameter description: " .. m)
return table.concat{'
', type, ' ', what, '', optional, '
'}
end)
end
function actions.returns(info)
return discount(info[1])
end
function actions.example(info)
return discount(info[1])
end
function actions.sketch(info)
return discount(info[1])
end
actions['function'] = function(info)
local arg_delim = info.has_table_args and {'{','}'} or {'(',')'}
local out = {
'
',
}
else
error("Unhandled module subtype: " .. info.type)
end
end
out[#out+1] = '
'
out[#out+1] = '
'
-- create detailed reference
for _,info in ipairs(info[4]) do
local s = actions[info.type](info)
out[#out+1] = s:gsub('{{MODULE}}', modname)
end
out[#out+1] = '
'
return table.concat(out)
end
-- title
function actions.title(info)
--return table.concat{'
', info[1], '
'}
return ""
end
-- build module overview
function actions.preprocess(doctree)
local out = {}
out[#out+1] = '
'
for _, info in ipairs(filter(doctree, function(v) return v.type == 'module' end)) do
out[#out+1] = table.concat{
'
'
local mod_overview = {type = 'section', 'Modules', '', 2, table.concat(out)}
for i = 1,#doctree do
if doctree[i][1] == 'Introduction' then
table.insert(doctree, i+1, mod_overview)
break
end
end
return doctree
end
function actions.postprocess(out)
return table.concat{[[
hump - LÖVE Helper Utilities for More Productivity