Module:CRTTypeList
Documentation for this module may be created at Module:CRTTypeList/doc
-- Module:CRTTypeList
-- Dynamically generates a list of CRT type buttons by querying
-- pre-computed type category pages with semantic properties.
-- Much faster than scanning all CRT model pages.
local p = {}
local function trim(s)
if s == nil then return nil end
s = tostring(s)
s = s:gsub('^%s+', ''):gsub('%s+$', '')
if s == '' then return nil end
return s
end
function p.list(frame)
-- Query type category pages (fast - only queries category pages, not all CRTs)
local queryWikitext =
'{{#ask:\n' ..
' [[Is CRT type category::Yes]]\n' ..
' |?CRT type name\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
' |mainlabel=-\n' ..
' |limit=500\n' ..
' |searchlabel=\n' ..
'}}'
local queryResult = frame:preprocess(queryWikitext)
-- Extract type names from result
local typesList = {}
if queryResult then
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
local crtType = trim(cellContent:gsub('<[^>]+>', ''))
if crtType and crtType ~= '' then
table.insert(typesList, crtType)
end
end
end
-- Sort alphabetically
table.sort(typesList)
if #typesList == 0 then
return '<p><em>No CRT types found.</em></p>'
end
-- Build the output: render each type using Template:CRT type entry
local output = {}
for _, crtType in ipairs(typesList) do
local templateCall = '{{CRT type entry|type=' .. crtType .. '}}'
table.insert(output, frame:preprocess(templateCall))
end
return table.concat(output, '\n')
end
return p