Module:Documentation: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(more efficient code for the subpages link)
(make startBox, content and endBox accessible from #invoke)
Line 41: Line 41:


----------------------------------------------------------------------------
----------------------------------------------------------------------------
-- Argument processing
-- Main functions
----------------------------------------------------------------------------
----------------------------------------------------------------------------


function p.main(frame)
local function makeInvokeFunc(funcName)
local args = getArgs(frame, {
return function (frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
valueFunc = function (key, value)
if type(value) == 'string' then
value = value:match('^%s*(.-)%s*$') -- Remove whitespace.
if type(value) == 'string' then
value = value:match('^%s*(.-)%s*$') -- Remove whitespace.
if key == 'heading' or value ~= '' then
return value
if key == 'heading' or value ~= '' then
return value
else
return nil
end
else
else
return nil
return value
end
end
else
return value
end
end
end
})
return p[funcName](args)
})
end
return p._main(args)
end
end

----------------------------------------------------------------------------
-- Main functions
----------------------------------------------------------------------------

p.main = makeInvokeFunc('_main')


function p._main(args)
function p._main(args)
Line 72: Line 80:
.attr('id', 'template-documentation')
.attr('id', 'template-documentation')
.addClass('template-documentation iezoomfix')
.addClass('template-documentation iezoomfix')
.wikitext(p.startBox(args))
.wikitext(p._startBox(args))
.wikitext(p.content(args))
.wikitext(p._content(args))
.tag('div')
.tag('div')
.css('clear', 'both') -- So right or left floating items don't stick out of the doc box.
.css('clear', 'both') -- So right or left floating items don't stick out of the doc box.
.done()
.done()
.done()
.done()
.wikitext(p.endBox(args))
.wikitext(p._endBox(args))
.wikitext(p.addTrackingCategories())
.wikitext(p.addTrackingCategories())
return tostring(root)
return tostring(root)
Line 120: Line 128:
end
end


function p.startBox(args)
p.startBox = makeInvokeFunc('_startBox')

function p._startBox(args)
-- Arg processing from {{documentation}}.
-- Arg processing from {{documentation}}.
local preload = args.preload -- Allow custom preloads.
local preload = args.preload -- Allow custom preloads.
Line 214: Line 224:
end
end


function p.content(args)
p.content = makeInvokeFunc('_content')

function p._content(args)
local content = args.content
local content = args.content
if not content then
if not content then
Line 234: Line 246:
end
end


function p.endBox(args)
p.endBox = makeInvokeFunc('_endBox')

function p._endBox(args)
-- Argument processing in {{documentation}}.
-- Argument processing in {{documentation}}.
local preload = args.preload -- Allow custom preloads.
local preload = args.preload -- Allow custom preloads.