Jump to content

Module:Format TemplateData/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2403:6200:8890:4a95:3aec:e4ff:fe80:8fea (talk) at 18:38, 11 March 2019 (editor). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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:
    1. A localized version, markup etc. stripped off, in JSON format.
    2. 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.

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)
  1. atleast
    optional
    nil or minimal version request
Returns: string or false
TemplateData.getPlainJSON(adapt)
Reduce enhanced JSON information to MediaWiki JSON
  1. adapt
    string, with JSON (enhanced)
Returns: string, with JSON (MediaWiki )
TemplateData.test(adapt, arglist)
Simulation of template functionality
  1. adapt
    table, #invoke parameters
  2. arglist
    table, template parameters
Returns: string

Usage

Currently focusing on one template only:

Dependencies