Module:Error: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
simplify argument-grabbing code
simplify code some more and trim whitespace from the message
Line 6: Line 6:


local function _error(args)
local function _error(args)
local s = args.message or args[1] or error('no message specified', 2)
local message = args.message or args[1] or error('no message specified', 2)
message = mw.ustring.match(tostring(message), '^%s*(.*%S)') or '' -- Convert message to string and trim whitespace.
local tag = mw.ustring.lower(tostring(args.tag))
local tag = mw.ustring.lower(tostring(args.tag))


-- Work out what html tag we should use.
-- Work out what html tag we should use.
if not (tag == 'p' or tag == 'span' or tag == 'div') then
local t
if tag == 'p' or tag == 'span' or tag == 'div' then
tag = 'strong'
t = tag
else
t = 'strong'
end
end
local root = HtmlBuilder.create(t)


-- Generate the html.
-- Generate the html.
local root = HtmlBuilder.create(tag)
root
root
.addClass('error')
.addClass('error')
.wikitext(tostring(s))
.wikitext(message)


return tostring(root)
return tostring(root)
Line 48: Line 46:
end
end


local args = origArgs
return _error(args)
return _error(args)
end
end