dev
Documentation icon Module documentation
[view] [edit] [history] [purge]
Documentation icon Module documentation

See Global Lua Modules/Error.

Subpages

--- Error is used to implement [[Template:Error]].
-- This module is a copy of [[wikipedia:Module:Error|Wikipedia's Error module]].
-- @module  Error
-- @author  [[wikipedia:User:Mr. Stradivarius|Mr. Stradivarius]] et al.
-- @release stable
local getArgs = require('Module:Arguments').getArgs
local p = {}

--- Entrypoint for [[Template:Error]].
-- @function p.error
-- @param    {table} frame The Scribunto frame.
-- @return   {string} An HTML object with class "error" containing the message
-- specified in the frame's arguments.
function p.error(frame)
    local args = getArgs(frame)
    return _error(args)
end

function p._error(args)
	local msg = tostring(args.message or args[1])
	if not msg then
		error('no message specified', 2)
	end
	
    local tag = mw.ustring.lower(tostring(args.tag))
    if not (tag == 'p' or tag == 'span' or tag == 'div') then
        tag = 'strong'
    end

    return tostring(mw.html.create(tag):addClass('error'):wikitext(msg))
end

return p