Module:Documentation: Difference between revisions

put argument names into a config file for easy porting to other wikis
(make startBox, content and endBox accessible from #invoke)
(put argument names into a config file for easy porting to other wikis)
Line 1:
-- This module implements {{documentation}}.
 
----------------------------------------------------------------------------
-- Configuration
----------------------------------------------------------------------------
 
-- Here you can set the values of the parameters and messages used in this module, so that it
-- can be easily ported to other wikis.
 
local cfg = {}
 
-- Argument names
-- The following are all names of arguments that affect the behaviour of {{documentation}}.
-- The comments next to the configuration values are the effects that the argument has
-- on the module. (Not the effects of the argument names themselves.)
 
cfg.livepageArg = 'livepage' -- Name of the live template; used in {{template sandbox notice}}.
cfg.headingArg = 'heading' -- Custom heading used in the start box.
cfg.preloadArg = 'preload' -- Custom preload page for creating documentation.
cfg.headingStyleArg = 'heading-style' -- Custom CSS style for the start box heading.
cfg.contentArg = 'content' -- Passes documentation content directly from the {{documentation}} invocation.
cfg.linkBoxArg = 'link box' -- Specifies a custom link box (end box) or prevents it from being generated.
 
----------------------------------------------------------------------------
-- End configuration
----------------------------------------------------------------------------
 
-- Get required modules.
Line 46 ⟶ 71:
local function makeInvokeFunc(funcName)
return function (frame)
local headingArg = cfg.headingArg
local args = getArgs(frame, {
valueFunc = function (key, value)
if type(value) == 'string' then
value = value:match('^%s*(.-)%s*$') -- Remove whitespace.
if key == 'heading'headingArg or value ~= '' then
return value
else
Line 99 ⟶ 125:
.css('clear', 'both')
.done()
.wikitext(frame:expandTemplate{title = 'template sandbox notice', args = {args[cfg.livepagelivepageArg]}})
return tostring(root)
else
Line 132 ⟶ 158:
function p._startBox(args)
-- Arg processing from {{documentation}}.
local preload = args[cfg.preloadpreloadArg] -- Allow custom preloads.
local heading = args[cfg.headingheadingArg] -- Blank values are not removed.
local headingStyle = args['heading-style'cfg.headingStyleArg]
local content = args[cfg.contentcontentArg]
local docspace = p.docspace()
local docname = args[1] -- Other docname, if fed.
Line 227 ⟶ 253:
 
function p._content(args)
local content = args[cfg.contentcontentArg]
if not content then
local docpage = args[1]
Line 250 ⟶ 276:
function p._endBox(args)
-- Argument processing in {{documentation}}.
local preloadcontent = args[cfg.preload -- Allow custom preloads.contentArg]
local contentlinkBox = args[cfg.linkBoxArg] -- So "link box=off" works.content
local linkBox = args['link box'] -- So "link box=off" works.
local docspace = p.docspace()
local docname = args[1] -- Other docname, if fed.