Module:Sandbox/The Earwig/AfC submission

Revision as of 02:53, 17 February 2021 by imported>The Earwig (prototype main template detection)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/The Earwig/AfC submission/doc

local p = {}

-- local templateRegex = "[Aa][Ff][Cc] submission"
local templateRegex = "User:The Earwig/Sandbox/AfC submission"

-- Is this the first submission template on the page?
-- Later templates emit nothing, only recording the submission state.
local function isMainTemplate(args, text)
	local match = mw.ustring.match(text, "%{%{%s*"..templateRegex..".-%|%s*ts%s*=([^|}]*)")
	return match == args.ts
end

-- Render the AfC submission template.
local function render(frame, args, text)
	return frame:expandTemplate{ title = "AfC submission", args = args }
end

function p.main(frame)
	local args = frame:getParent().args
	local text = mw.title.getCurrentTitle():getContent()
	if isMainTemplate(args, text) then
		return render(frame, args, text)
	end
end

return p