Module:Sanctions/AlertHelper: Difference between revisions
Appearance
Content deleted Content added
m ProcrastinatingReader moved page Module:Sandbox/ProcrastinatingReader/two to Module:Sanctions/AlertHelper without leaving a redirect: out of sandbox |
use live |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local checkIfValidTopic = require('Module:Sanctions |
local checkIfValidTopic = require('Module:Sanctions').checkIfValidTopic |
||
local function tableContains(needle, haystack) |
local function tableContains(needle, haystack) |
||
Line 28: | Line 28: | ||
if checkIfValidTopic(topic) then |
if checkIfValidTopic(topic) then |
||
return frame:expandTemplate { |
return frame:expandTemplate { |
||
title = 'Gs/alert |
title = 'Gs/alert', |
||
args = { topic } |
args = { topic } |
||
} |
} |
||
Line 34: | Line 34: | ||
-- return to ds template, let it error if not recognised |
-- return to ds template, let it error if not recognised |
||
return frame:expandTemplate { |
return frame:expandTemplate { |
||
title = 'Ds/alert |
title = 'Ds/alert', |
||
args = { topic } |
args = { topic } |
||
} |
} |
Revision as of 12:51, 12 February 2022
local p = {}
local getArgs = require('Module:Arguments').getArgs
local checkIfValidTopic = require('Module:Sanctions').checkIfValidTopic
local function tableContains(needle, haystack)
for _, v in pairs(haystack) do
if v == needle then
return true
end
end
return false
end
local function syntaxHelp()
return [[<span class="error">{{para|topic}} not specified. Available options:</span><div style="border-left: 5px dashed black; border-right: 5px dashed black; border-bottom: 5px dashed black; padding-left: 0.5em; padding-right: 0.5em; padding-bottom: 0.5em;">
{{Ds/topics/table}}
{{Gs/topics/table|subst=y}}
</div>]]
end
function p.build(frame, args)
local topic = args[1] or args['topic']
if not topic then
return frame:preprocess(syntaxHelp())
end
if checkIfValidTopic(topic) then
return frame:expandTemplate {
title = 'Gs/alert',
args = { topic }
}
else
-- return to ds template, let it error if not recognised
return frame:expandTemplate {
title = 'Ds/alert',
args = { topic }
}
end
end
function p.main(frame)
local args = getArgs(frame, {
wrappers = {
'Template:Alert',
'Template:Alert/sandbox'
}
})
return p.build(frame, args)
end
return p