Module:Higher education task force: Difference between revisions

Content deleted Content added
No edit summary
m Protected "Module:Higher education task force": High-risk template or module: 5198 transclusions (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
 
(135 intermediate revisions by 2 users not shown)
Line 1:
require("strict")
--[[------------------------< generateTaskforceParameters >---------------------------------
local yesNo = require("Module:Yesno")
Generates the WikiProject banner parameters for a comma-separated list of task force codes.
local getArgs = require("Module:Arguments").getArgs
local banner = require("Module:WikiProject_banner")
local paramsStrp = ""{}
 
--[[------------------------< generateTaskforceParameters_main >---------------------------------
Parameters:
Internal function to retrieve data for a task force.
* frame: The frame object.
]]----------------------------------------------------------------------------
function p._main(args, data)
local dataModule = require('Module:Higher education task force/data')
local taskForceCode = args.code or args[1]
local taskForceData
 
if taskForceCode then
taskForceCode = taskForceCode:match('^%s*(.-)%s*$'):lower() -- trim whitespace and put in lower case
taskForceData = dataModule[taskForceCode]
end
 
return taskForceData
end
 
--[[------------------------< getCanonicalCode >---------------------------------
Gets the canonical code for a task force. return tfData.canonicalCode
 
Returns:
* A string containing the WikiProject banner parameters for the task forces.
]]----------------------------------------------------------------------------
 
function p.generateTaskforceParameters(frame)
function p.main(frame)
local taskforcesStr = frame.args.taskforces
local args = getArgs(frame, { parentFirst = true })
return p._main(args)
end
 
-- Takes an input string "r" in the form "|a=b" (no spaces around the =) used in templates and adds it to the table
function p.tab2arg(trable,r)
local t = mw.text.split(r, "=", true, true) -- Split by comma, trim whitespace, remove empty strings
local x = mw.text.split(t[1], "|", true, true) -- Split by comma, trim whitespace, remove empty strings
trable[x[2] ]=t[2]
return trable
end
 
-- Adds an element to a table (syntactic sugar)
function p.ma1(frame,s1,s2)
frame[s1]=s2
end
 
--[[ pulls out our specially named parameter from the list of template-like args, and expands
it into the appropriate task force table entries
]]--
function p.fudgeTaskforceParameters(frame)
local args = getArgs(frame, { parentFirst = true })
local taskforcesStr = frame.args.taskforces""
taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
if not taskforcesStr then
return "oops"
end
 
local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
local paramsStr = ""
local tfCounter = 1
local trable=args
 
for _, code in ipairs(taskforceCodes) do
local tfData = p.getTaskForceData_main({code})
if tfData then
paramsStr = paramsStr .. trable = p.tab2arg(trable,string.format("|tf %d=yes%dyes", tfCounter,tfCounter))
paramsStrtrable = paramsStr p.. tab2arg(trable,string.format("|TF_%d_LINK=%s", tfCounter, tfData.link))
paramsStrtrable = paramsStr p.. tab2arg(trable,string.format("|TF_%d_NAME=%s", tfCounter, tfData.name))
paramsStrtrable = paramsStr p.. tab2arg(trable,string.format("|TF_%d_NESTED=%s", tfCounter, tfData.nested))
paramsStrtrable = paramsStr p.. tab2arg(trable,string.format("|TF_%d_IMAGE=%s", tfCounter, tfData.image))
paramsStrtrable = paramsStr p.. tab2arg(trable,string.format("|TF_%d_MAIN_CAT=%s", tfCounter, tfData.category))
paramsStr = paramsStr .. "\n"
tfCounter = tfCounter + 1
end
end
frame.args=trable
return frame
end
 
-- More or less a wrapper for WikiProject Banner with some argument sweetening
return paramsStr
function p.hetf_banner(frame)
local oframe=frame
frame=p.fudgeTaskforceParameters(frame)
 
return banner.main(oframe)
end
 
 
function p.printargs(frame)
local str=getArgs(frame, { parentFirst = true })
return str[1]
end
 
 
 
p[''] = function (frame) return p._main(frame.args) end
 
return paramsStrp