Module: Error

From A Wiki of Ice and Fire
Jump to: navigation, search

Documentation for this module may be created at Module:Error/doc

-- This module implements {{error}}.
local getArgs = require('Module:Arguments').getArgs

local p = {}

local function _error(args)
    local tag = mw.ustring.lower(tostring(args.tag))

    -- Work out what html tag we should use.
    if not (tag == 'p' or tag == 'span' or tag == 'div') then
        tag = 'strong'
    end

    -- Generate the html.
    return tostring(mw.html.create(tag)
        :addClass('error')
        :wikitext(tostring(args.message or args[1] or error('no message specified', 2)))
    )
end

function p.error(frame)
    local args = getArgs(frame)
    if args.message == "" then
        args.message = nil
    end
    return _error(args)
end

return p