Module:BrandSeries
-- Module:BrandSeries -- Generates a series breakdown table for a brand's CRTs -- Shows only series that have CRTs for the specified brand
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.seriesTable(frame) local args = frame.args local parent = frame:getParent() if parent then args = parent.args end
local brand = trim(args.brand) or trim(args[1])
if not brand then return 'Error: brand parameter required' end
-- First, get all series from Category:Series local seriesQuery = '30 Series@@60 Series@@A Series@@Cineos@@D-Series@@F Series@@I'Art@@I'Art Pro@@InteriArt@@K Series@@Kirara Basso@@PVM@@Profeel Pro@@SuperFlat@@TruFlat@@Video Capsule@@Videosphere@@WEGA@@XBR' local seriesResult = frame:preprocess(seriesQuery)
if not seriesResult or seriesResult == then return "No series found." end
-- Parse series names local seriesList = {} for series in seriesResult:gmatch('[^@@]+') do local s = trim(series) if s then table.insert(seriesList, s) end end
-- Sort alphabetically table.sort(seriesList)
-- For each series, count how many CRTs belong to this brand local rows = {} for _, series in ipairs(seriesList) do local countQuery = string.format( '0', brand, series ) local countResult = frame:preprocess(countQuery) local count = tonumber(trim(countResult)) or 0
if count > 0 then -- Build the browse link local browseLink = string.format( 'Browse', brand, series ) local browseHtml = frame:preprocess(browseLink)
table.insert(rows, { series = series, count = count, browse = browseHtml }) end end
-- If no series found for this brand if #rows == 0 then return "No series-assigned models for this brand." end
-- Build the table local output = {} table.insert(output, '{| class="wikitable"') table.insert(output, '|-') table.insert(output, '! Series !! Count !! Browse')
for _, row in ipairs(rows) do table.insert(output, '|-') table.insert(output, string.format('| %s || %d || %s', row.series, row.count, row.browse)) end
table.insert(output, '|}')
return table.concat(output, '\n') end
return p