Module:Table/Wrench: Difference between revisions

From Growtopia
Jump to navigationJump to search
>HashJona
mNo edit summary
>HashJona
mNo edit summary
Line 10: Line 10:
local lines = mw.text.split(data, "\n")
local lines = mw.text.split(data, "\n")
local results = {}
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
for _, line in ipairs(lines) do
         line = mw.text.trim(line)
         line = mw.text.trim(line)
         if line ~= "" then
         if line ~= "" then
         
            line = line:gsub("%s*%$%$%$", "")
            
            
             local parts = mw.text.split(line, "|")
             local parts = mw.text.split(line, "|")
             local month = parts[1] or ""
             local month = parts[1] or "-"
             local item  = parts[2] or ""
             local item  = parts[2] or ""
 
           
             -- 4. Insert into a Lua table
             local key = months[month]
             table.insert(results, {
             if  results[key] == nil then
                month = mw.text.trim(month),
            results[key] = '|-\n|' .. month .. '\n|' .. item
                item  = mw.text.trim(item),
            else
             })
            results[key] = results[key] .. '\n|' .. item
             end
         end
         end
end
end
     return table.concat(results, '\n')
local output = {}
for _, row in ipairs(results) do
        table.insert(output, "1- " .. row.month .. ", 2-" .. row.item)
    end
 
     return table.concat(output, '\n')
end
end


return p
return p

Revision as of 12:42, 5 April 2025

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