Module:Table/Wrench

From Growtopia
Revision as of 12:42, 5 April 2025 by >HashJona
Jump to navigationJump to search

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

local p = {}

function p.build_table(frame) 
	local args = frame:getParent().args
	local data = args['data'] or ''
	if args == '' then
		return ''
	end
	
	local lines = mw.text.split(data, "\n")
	local results = {}
	local months = {
		January = 1,
		February = 2,
		March = 3,
		April = 4,
		May = 5,
		June = 6,
		July = 7,
		August = 8,
		September = 9,
		October = 10,
		November = 11,
		December = 12,
		['-'] = 13
	}
	
	for _, line in ipairs(lines) do
        line = mw.text.trim(line)
        if line ~= "" then
           
            local parts = mw.text.split(line, "|")
            local month = parts[1] or "-"
            local item  = parts[2] or ""
            
            local key = months[month]
            if  results[key] == nil then 
            	results[key] = '|-\n|' .. month .. '\n|' .. item
            else
            	results[key] = results[key] .. '\n|' .. item
            end
        end
	end
    return table.concat(results, '\n')
end

return p