Module:Format TemplateData/doc
Appearance
![]() | This is a documentation subpage for Module:Format TemplateData. It may contain usage information, categories and other content that is not part of the original module page. |
![]() | This page in a nutshell: To use this module in a documentation page, use {{Format TemplateData}}. The below is an essay on the reasons for this module's existence, and documentation of the module itself. |
TemplateData
– Module with auxilary functions for template documentation, especially by TemplateData.
Core functionality is improved presentation on documentation pages.
Editor
General workflow
- An attempt is made to read the JSON object (string) from passed template parameters.
- If this failed, the source code of the current and the documentation page is searched for
<templatedata>
elements. - Two representations are obtained from the JSON object input:
- A localized version, markup etc. stripped off, in JSON format.
- An HTML structure, basically similar to the MediaWiki representation, possibly with table of the parameters, with enhanced features.
- The result of the template is a visible documentation with markup, followed by a hidden
<templatedata>
element. This is done for the export and corresponds to the MediaWiki guidelines.- If current page has been identified as documentation page the hidden
<templatedata>
is suppressed, and those pages do not appear separately in Special:PagesWithProp/templatedata.
- If current page has been identified as documentation page the hidden
Functions for templates
Details
- f
- Improve TemplateData-presentation; used in Template:TemplateData
- Parameters of template transclusion environment (all optional):
- 1
- JSON string or
<templatedata>
object - JSON
- JSON string
- (precedes 1)
- Transition from
<templatedata>
objects with pipe symbols needs special attention: Pipes are to be represented as{{!}}
, on double curly brackets one should be encoded by HTML entity. - TOC
1
– Insert table of contents after general purpose descriptions; but before parameter list, if present- lazy
1
– Presentation only, do not generate an effective data block- For general method descriptions.
- debug
1
– developer mode
- Parameters of
#invoke
for particular project adaption (all optional):- cat
- Title of a maintenance category on invalid parameter value etc.
- debug
- Development mode, if provided and not equal
0
- docpageCreate
- Pattern for creation of subpage names;
%s/Doku
- docpageDetect
- Pattern for recognition of subpage names;
/Doku$
- msgDescMiss
- Localisation: complaint text on missing
description
- Returns: HTML code; and/or error message, probably with
class="error"
- failsafe
- Version identification:
2022-03-10
- Optional additional parameter
1
– requested minimal version identification- Returns: (empty), if minimal version condition not matched
Examples (test page)
A test page illustrates practical use.
Functions for Lua modules (API)
Some functions described above can be used by other modules:
local lucky, TemplateData = pcall( require, "Module:TemplateData" )
if type( TemplateData ) == "table" then
TemplateData = TemplateData.TemplateData()
else
-- failure; TemplateData is the error message
return "<span class='error'>" .. TemplateData .. "</span>"
end
- TemplateData.failsafe(atleast)
-
- atleast
optional
nil or minimal version request
- atleast
- Returns: string or false
- TemplateData.getPlainJSON(adapt)
- Reduce enhanced JSON information to MediaWiki JSON
- adapt
string, with JSON (enhanced)
- adapt
- Returns: string, with JSON (MediaWiki )
- TemplateData.test(adapt, arglist)
- Simulation of template functionality
- adapt
table,#invoke
parameters - arglist
table, template parameters
- adapt
- Returns: string
Usage
Currently focusing on one template only: