Module: Error: Difference between revisions

From A Wiki of Ice and Fire
Jump to: navigation, search
Abjiklam (talk | contribs)
Created page with "local getArgs = require('Module:Arguments').getArgs local p = {} function p.error(frame) local args = getArgs(frame) local message = args.message or 'Unknown error'..."
 
Abjiklam (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- This module implements {{error}}.
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


local p = {}
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)
function p.error(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)
     local message = args.message or 'Unknown error'
     if args.message == "" then
     return error(message, 2)
        args.message = nil
    end
     return _error(args)
end
end


return p
return p

Latest revision as of 16:29, 26 October 2022

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