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{ '
', '<',htype,'>', info[1], '^top', discount(info[4]), '
' } end return table.concat{ '
', '<',htype,'>', info[1], '^top', '
', discount(info[4]), '
', '
' } 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 = { '
', '

', 'function ', info[1], '', '', arg_delim[1], info[2], arg_delim[2], '', '^top

', discount(info[4]) } -- parameter list local parameters = filter(info[5], function(v) return v.type == 'parameters' end) out[#out+1] = '
' out[#out+1] = 'Parameters:' if #parameters == 0 then out[#out+1] = '
None
' else for _, r in ipairs(parameters) do out[#out+1] = actions.parameters(r) end end out[#out+1] = '
' -- returns list local returns = filter(info[5], function(v) return v.type == 'returns' end) out[#out+1] = '
' out[#out+1] = 'Returns:' if #returns == 0 then out[#out+1] = '
Nothing
' else for _, r in ipairs(returns) do out[#out+1] = actions.returns(r) end end out[#out+1] = '
' -- examples local examples = filter(info[5], function(v) return v.type == 'example' end) assert(#examples > 0, "No examples given for function " .. info[1] .. "()") out[#out+1] = '
' out[#out+1] = #examples > 1 and 'Examples:' or 'Example:' for _,s in ipairs(examples) do out[#out+1] = actions.example(s) end out[#out+1] = '
' -- sketch local sketch = filter(info[5], function(v) return v.type == 'sketch' end) if #sketch > 0 then out[#out+1] = '
' out[#out+1] = #sketch > 1 and 'Sketches:' or 'Sketch:' for _,s in ipairs(sketch) do out[#out+1] = actions.sketch(s) end out[#out+1] = '
' end out[#out+1] = '
' return table.concat(out) end -- module function actions.module(info) local modname = info[1] local out = { '
', '

', modname, '^top

', '
', discount(info[3]), '
' } -- create module overview out[#out+1] = '
' out[#out+1] = '

Module overview

' out[#out+1] = '
' for _,info in ipairs(info[4]) do if info.type == 'function' then out[#out+1] = table.concat{ '
', '', info[1], '()', '', '
', info[3], '
', } elseif info.type == 'section' then out[#out+1] = table.concat{ '
', '', info[1], '', '
', info[2], '
', } 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{ '
', info[1], '
', '
', info[2], '
', } end out[#out+1] = '
' 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 ]], out:gsub('{{MODULE}}', ''):gsub('', ''), "" } end return actions