Module:ComponentTriggers: Difference between revisions

From Resonite Wiki
fix type field
add hidden column
Line 15: Line 15:
local name = templateFrame.args[argI]
local name = templateFrame.args[argI]
local type = templateFrame.args[argI + 1]
local type = templateFrame.args[argI + 1]
local description = templateFrame.args[argI + 2]
local hidden = templateFrame.args[argI + 2]
local description = templateFrame.args[argI + 3]


if name == nil then
if name == nil then
break
break
end
if hidden == "true" then
hidden = "✓"
else
hidden = "X"
end
end


Line 31: Line 38:
body = body.."|<code>"..name.."</code>\n"
body = body.."|<code>"..name.."</code>\n"
body = body.."|'''"..type.."'''\n"
body = body.."|'''"..type.."'''\n"
body = body.."|"..hidden.."\n"
body = body.."|"..description.."\n"
body = body.."|"..description.."\n"
i = i + 1
i = i + 1

Revision as of 05:56, 17 March 2025

Documentation for this module may be created at Module:ComponentTriggers/doc

-- test in console:
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentTriggers",args={"name", "name", "desc"}}:newChild{title="Module:Test",args={}})
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentTriggers",args={"name", "name", "{{stub}}"}}:newChild{title="Module:Test",args={}})
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentTriggers",args={"name", "name", ""}}:newChild{title="Module:Test",args={}})
local p = {}

function p.main(frame)
	local body = ""
	local isStub = false
	local templateFrame = frame:getParent()
	local i = 0

	while true do
		local argI = i * 3 + 1
		local name = templateFrame.args[argI]
		local type = templateFrame.args[argI + 1]
		local hidden = templateFrame.args[argI + 2]
		local description = templateFrame.args[argI + 3]

		if name == nil then
			break
		end
		
		if hidden == "true" then
			hidden = "✓"
		else
			hidden = "X"
		end

		description = mw.text.trim(description)
		if description == "{{stub}}" then isStub = true end
		if description == "" then
			isStub = true
		else
			--description = "<translate>" .. description .. "</translate>"
		end
		body = body.."|-\n"
		body = body.."|<code>"..name.."</code>\n"
		body = body.."|'''"..type.."'''\n"
		body = body.."|"..hidden.."\n"
		body = body.."|"..description.."\n"
		i = i + 1
	end
	if isStub then body = body.."[[Category:ComponentStubs]]" end
	return body
end

return p