Module:Documentation/Template

local p = {} local h = {}

local i18n = require("Module:I18n") local s = i18n.getString local utilsLayout = require("Module:UtilsLayout") local utilsMarkup = require("Module:UtilsMarkup")

function p.Examples(frame) local args = frame:getParent.args return p.examples(args) end

function p.examples(templateExamples) local examples = h.examples(templateExamples) if not templateExamples.vertical then local tableData = { hideEmptyColumns = true, rows = { { s("input"), s("output"), s("categoriesAdded"), header = true } }		}		for _, example in ipairs(examples) do			table.insert(tableData.rows, {example.input, example.output, example.categoryList}) end return utilsLayout.table(tableData) else local result = "" for _, example in ipairs(examples) do			local headerStyles = { ["width"] = "5rem" -- for alignment. See Template:Letter/Documentation for an example of why this is needed }			result = result .. utilsLayout.table({				hideEmptyRows = true,				rows = {					{						{ header = true, content= s("input"), styles = headerStyles}, 						example.input,					},					{						{ header = true, content = s("output"), styles = headerStyles}, 						example.output					},					{						{ header = true, content = s("categoriesAdded"), styles = headerStyles },						example.categoryList					},				}			}) .. "\n" end return result end end

function h.examples(templateExamples) local result = {} for _, example in ipairs(templateExamples) do		local input = mw.text.unstripNoWiki(example) local output = mw.getCurrentFrame:preprocess(mw.text.decode(input)) input = mw.text.trim(input) if string.find(input, "\n") or templateExamples.vertical then input = utilsMarkup.pre(input, {				wrapLines = false			}) else input = utilsMarkup.code(mw.text.nowiki(input)) end local output, categories = utilsMarkup.stripCategories(output) local output = utilsMarkup.killBacklinks(output) local categoryList = utilsMarkup.bulletList(categories) table.insert(result, {			input = input, 			output = output, 			categoryList = categoryList		}) end return result end

i18n.loadStrings({	en = {		input = "Input",		output = "Output",		categoriesAdded = "Categories added",	} })

return p