Module:Documentation: Difference between revisions
Jump to navigation
Jump to search
m>Mr. Stradivarius make startBox, content and endBox accessible from #invoke |
m>Mr. Stradivarius put argument names into a config file for easy porting to other wikis |
||
Line 1: | Line 1: | ||
-- This module implements {{documentation}}. | -- 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. | -- Get required modules. | ||
Line 46: | Line 71: | ||
local function makeInvokeFunc(funcName) | local function makeInvokeFunc(funcName) | ||
return function (frame) | return function (frame) | ||
local headingArg = cfg.headingArg | |||
local args = getArgs(frame, { | local args = getArgs(frame, { | ||
valueFunc = function (key, value) | valueFunc = function (key, value) | ||
if type(value) == 'string' then | if type(value) == 'string' then | ||
value = value:match('^%s*(.-)%s*$') -- Remove whitespace. | value = value:match('^%s*(.-)%s*$') -- Remove whitespace. | ||
if key == | if key == headingArg or value ~= '' then | ||
return value | return value | ||
else | else | ||
Line 99: | Line 125: | ||
.css('clear', 'both') | .css('clear', 'both') | ||
.done() | .done() | ||
.wikitext(frame:expandTemplate{title = 'template sandbox notice', args = {args. | .wikitext(frame:expandTemplate{title = 'template sandbox notice', args = {args[cfg.livepageArg]}}) | ||
return tostring(root) | return tostring(root) | ||
else | else | ||
Line 132: | Line 158: | ||
function p._startBox(args) | function p._startBox(args) | ||
-- Arg processing from {{documentation}}. | -- Arg processing from {{documentation}}. | ||
local preload = args. | local preload = args[cfg.preloadArg] -- Allow custom preloads. | ||
local heading = args. | local heading = args[cfg.headingArg] -- Blank values are not removed. | ||
local headingStyle = args[ | local headingStyle = args[cfg.headingStyleArg] | ||
local content = args. | local content = args[cfg.contentArg] | ||
local docspace = p.docspace() | local docspace = p.docspace() | ||
local docname = args[1] -- Other docname, if fed. | local docname = args[1] -- Other docname, if fed. | ||
Line 227: | Line 253: | ||
function p._content(args) | function p._content(args) | ||
local content = args. | local content = args[cfg.contentArg] | ||
if not content then | if not content then | ||
local docpage = args[1] | local docpage = args[1] | ||
Line 250: | Line 276: | ||
function p._endBox(args) | function p._endBox(args) | ||
-- Argument processing in {{documentation}}. | -- Argument processing in {{documentation}}. | ||
local content = args[cfg.contentArg] | |||
local content = args. | local linkBox = args[cfg.linkBoxArg] -- So "link box=off" works. | ||
local linkBox = args[ | |||
local docspace = p.docspace() | local docspace = p.docspace() | ||
local docname = args[1] -- Other docname, if fed. | local docname = args[1] -- Other docname, if fed. |