Module:Documentation: Difference between revisions
make startBox, content and endBox accessible from #invoke
m>Mr. Stradivarius (more efficient code for the subpages link) |
m>Mr. Stradivarius (make startBox, content and endBox accessible from #invoke) |
||
Line 41: | Line 41: | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
-- | -- Argument processing | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
function | local function makeInvokeFunc(funcName) | ||
return function (frame) | |||
local args = getArgs(frame, { | |||
valueFunc = function (key, value) | |||
if type(value) == 'string' then | |||
value = value:match('^%s*(.-)%s*$') -- Remove whitespace. | |||
if key == 'heading' or value ~= '' then | |||
return value | |||
else | |||
return nil | |||
end | |||
else | |||
return value | return value | ||
end | end | ||
end | end | ||
}) | |||
return p[funcName](args) | |||
end | |||
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. | .wikitext(p._startBox(args)) | ||
.wikitext(p. | .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. | .wikitext(p._endBox(args)) | ||
.wikitext(p.addTrackingCategories()) | .wikitext(p.addTrackingCategories()) | ||
return tostring(root) | return tostring(root) | ||
Line 120: | Line 128: | ||
end | end | ||
function p. | 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. | 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. | 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. |