Module:String/Templates

require('Module:LoadLib')(_G, {	string = 'Module:String',	{ 'Module:Constructor' },	color = 'Module:Color',	mctxt = 'Module:Mctxt' }, { autoloads = false })

local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax

local p = {}

--- -- Template:Repeat -- -- Repeats the given string a specified number of times --- function p.repeatF(frame) local args = getArgs(frame, { removeBlanks = false }) local s = args[1] or '' local num = args[2] or '1' local sep = args[3]

if num:match('[^%d%-%+]+') then return string.error('number expected, got "%s"', tonumber(num)) elseif 0 >= tonumber(num) then return string.error('repeat delimiter must be greater than 0, got %s', num) end

return p._repeat(s, num, sep) end

- -- Template:Code -- -- Creates a piece of formatted code. - function p.code(frame) local args = getArgs(frame, { removeBlanks = false, trim = false })

local code = args['code'] or args['c'] or args[1] local tmp = Boolean(yesno(args['inline'] or args['i'], not code:match('\n'))) local contentOnly = yesno(args['conly'] or args['contentonly'] or args['only'], false)

if not tmp and tmp ~= nil then tmp = false end

local inline = tmp ~= false and 1 or nil

return (args['lang'] or args['l']) and mw.getCurrentFrame:extensionTag('syntaxhighlight', code, {			inline = inline,			lang = args['lang'] or args['l'],			class = (args['class'] or args['cl'] or ) .. (contentOnly and ' contents-only' or )		}) or string.wrapHtml(code, ' ', {			class = 'code'		}) end

- -- Template: Style -- -- Makes making CSS easier. - function p.style(frame) local ret = {}

for prop, value in pairs(getArgs(frame)) do		table.push(ret, prop, ': ', value, '; ') end

return table.concat(ret, '') end

- -- Template: ClassList -- -- Creates an HTML Class List. - function p.classList(frame) local t = mergeArgsSyntax(getArgs(frame)) local ret = {}

for i, v in ipairs(t) do		table.push(ret, v)	end return table.concat(ret, ' ') end

- -- function: yes(text, size) -- -- Creates a "Yes" pictogram. - function p.yes(text, size) return mctxt._raw('&a✔') .. (text and ' ' .. color.colorText('Green', 'Yes') or '') end

- -- function: no(text, size) -- -- Creates a "No" pictogram. - function p.no(text, size) return mctxt._raw('&c✕') .. (text and ' ' .. color.colorText('Red', 'No') or '') end

- -- function: unknown(?text: boolean, ?size: number, ?altText: string, ?reason: string) -- -- Creates a "unknown" pictogram. - function p.unknown(text, size, altText, reason) return mctxt._raw('&7?') .. (text and ' ' or '') .. string.makeTitle((altText or (text and color.colorText('gray', 'Unknown')) or ''),			'This information is unknown' ..			(reason and ' ' .. reason or '') .. '. If you know this information, please edit the page and replace this.')

end

return p