Jump to content

Module:Higher education task force test

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tduk (talk | contribs) at 19:17, 13 June 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
require("strict")
local yesNo = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs
local banner = require("Module:Higher_education_task_force_test2")
--local banner = require("Module:WikiProject_banner")
local p = {}

--[[------------------------< _main >---------------------------------
Internal function to retrieve data for a task force.
]]----------------------------------------------------------------------------
function p._oldmain(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

]]----------------------------------------------------------------------------


-- 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)
	local taskforcesStr = ""
    taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
	if not taskforcesStr then
		return "" 
 	end

	local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
	local tfCounter = 1
    local trable=args

	for _, code in ipairs(taskforceCodes) do
		local tfData = p._oldmain({code})
		if tfData then
            trable = p.tab2arg(trable,string.format("|tf %d=%dyes", tfCounter,tfCounter))
			trable = p.tab2arg(trable,string.format("|TF_%d_LINK=%s", tfCounter, tfData.link))
			trable = p.tab2arg(trable,string.format("|TF_%d_NAME=%s", tfCounter, tfData.name))
			trable = p.tab2arg(trable,string.format("|TF_%d_NESTED=%s", tfCounter, tfData.nested))
			trable = p.tab2arg(trable,string.format("|TF_%d_IMAGE=%s", tfCounter, tfData.image))
			trable = p.tab2arg(trable,string.format("|TF_%d_MAIN_CAT=%s", tfCounter, tfData.category))
			tfCounter = tfCounter + 1
		end
	end
    frame.args=trable
    return frame
end

function p.fudgeTaskforceParametersArgs(args)
	local taskforcesStr = ""
    taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
	if not taskforcesStr then
		return "" 
 	end

	local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
	local tfCounter = 1
    local trable=args

	for _, code in ipairs(taskforceCodes) do
		local tfData = p._oldmain({code})
		if tfData then
            trable = p.tab2arg(trable,string.format("|tf %d=%dyes", tfCounter,tfCounter))
			trable = p.tab2arg(trable,string.format("|TF_%d_LINK=%s", tfCounter, tfData.link))
			trable = p.tab2arg(trable,string.format("|TF_%d_NAME=%s", tfCounter, tfData.name))
			trable = p.tab2arg(trable,string.format("|TF_%d_NESTED=%s", tfCounter, tfData.nested))
			trable = p.tab2arg(trable,string.format("|TF_%d_IMAGE=%s", tfCounter, tfData.image))
			trable = p.tab2arg(trable,string.format("|TF_%d_MAIN_CAT=%s", tfCounter, tfData.category))
			tfCounter = tfCounter + 1
		end
	end
    return trable
end

function p.printtab(tab)
   local s=""
   for k,v in pairs(tab) do
      s=s..(k.." = "..v)
   end
   return s
end

function p.printargs(frame)
   local str=getArgs(frame,{wrappers = {"Module:WikiProject banner shell","banner shell",'Template:Banner holder'}})
   return p.printtab(str)
end



-- More or less a wrapper for WikiProject Banner with some argument sweetening
function p.omain(frame)
    local oframe=frame
--    local a=p.printargs(frame)
    local retv=p.fudgeTaskforceParameters(frame)

    local ret=banner.main(retv)
    return ret
end

p.main = function(frame)
	local args = getArgs(frame, {frameOnly = true})
	local raw_args = getArgs(frame, {frameOnly = true, removeBlanks = false})
    local retv=p.fudgeTaskforceParameters(args)
    local rretv=p.fudgeTaskforceParameters(raw_args)

    local i=banner.pinitialise(retv, rretv)
    local a=p.printargs(frame)
    local b=p.printtab(getArgs(frame))
	return i
end



p[''] = function (frame) return p._main(frame.args) end

return p