More actions
Content deleted Content added
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
Line 17: | Line 17: | ||
local backgrounds = { |
local backgrounds = { |
||
op = '# |
op = '#9141ac1A', |
||
flame_verbs = '# |
flame_verbs = '#e01b241A', |
||
flame_nouns = '# |
flame_nouns = '#e01b241A', |
||
storm_verbs = '# |
storm_verbs = '#3584e41A', |
||
storm_nouns = '# |
storm_nouns = '#3584e41A', |
||
life_verbs = '# |
life_verbs = '#33d17a1A', |
||
life_nouns = '# |
life_nouns = '#33d17a1A', |
||
necro_verbs = '# |
necro_verbs = '#77767b1A', |
||
necro_nouns = '# |
necro_nouns = '#77767b1A', |
||
nature_verbs = '# |
nature_verbs = '#ffffff1A', |
||
nature_nouns = '# |
nature_nouns = '#ffffff1A' |
||
} |
} |
||
Revision as of 19:40, 23 January 2025
Documentation for this module may be created at Module:ESTable/doc
local p = {}
-- Column mappings
local columns = {
op = 1,
flame_verbs = 2,
flame_nouns = 3,
storm_verbs = 4,
storm_nouns = 5,
life_verbs = 6,
life_nouns = 7,
necro_verbs = 8,
necro_nouns = 9,
nature_verbs = 10,
nature_nouns = 11
}
local backgrounds = {
op = '#9141ac1A',
flame_verbs = '#e01b241A',
flame_nouns = '#e01b241A',
storm_verbs = '#3584e41A',
storm_nouns = '#3584e41A',
life_verbs = '#33d17a1A',
life_nouns = '#33d17a1A',
necro_verbs = '#77767b1A',
necro_nouns = '#77767b1A',
nature_verbs = '#ffffff1A',
nature_nouns = '#ffffff1A'
}
-- Helper function to parse the source table
local function parseTable(frame, output)
local source = mw.text.split(frame:preprocess('{{:MediaWiki:ESTable}}'), '\n')
local data = {}
for i, line in ipairs(source) do
if line:match('^|%-') then
-- Skip separator lines
elseif line:match('^|') then
local row = {}
for cell in line:gmatch('|%s*([^||]+)%s*') do
table.insert(row, cell:match('^%s*(.-)%s*$'))
-- output = output .. cell .. '\n'
end
if #row > 0 then
table.insert(data, row)
end
end
end
return data, output
end
-- Helper function to trim whitespace and new lines
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
-- Main function to generate filtered table
function p.filter(frame)
local output = ''
local args = frame.args
local data, output = parseTable(frame, output)
-- if true then
-- return data
-- end
local selectedCols = {}
if args then
-- Trim whitespace from args
for k, v in pairs(args) do
args[k] = trim(v)
end
-- Remove empty arguments
for k, v in pairs(args) do
if v == '' then
args[k] = nil
end
end
-- Determine which columns to show
for k, v in pairs(args) do
if ((v ~= '') and columns[k]) then
table.insert(selectedCols, {name = k, index = columns[k]})
end
end
end
local bg = (args.bg ~= '')
-- Sort columns by their original index
table.sort(selectedCols, function(a, b) return a.index < b.index end)
-- for _, col in ipairs(selectedCols) do
-- output = output .. ' !! ' .. tostring(col.index)
-- end
-- output = output .. '\n\n'
-- Generate output table
output = output .. '{| class="wikitable"\n'
-- Header row
-- output = output .. '! OP'
-- for _, col in ipairs(selectedCols) do
-- local header = col.name:gsub("_", " "):gsub("^%l", string.upper)
-- output = output .. ' !! ' .. header
-- end
-- output = output .. '\n'
-- Data rows
local header = true
for _, row in ipairs(data) do
if (#row > 0) and (#selectedCols > 0) then
output = output .. '\n\n|-\n\n'
for _, col in ipairs(selectedCols) do
if header then
d = '!'
else
d = '|'
end
content = d
if bg then
content = content .. ' style="background-color: ' .. backgrounds[col.name] .. '" |'
end
content = content .. ' ' .. tostring(row[col.index]) .. ' ' .. d
output = output .. content
end
output = output:sub(1, -3)
-- output = output .. '\n'
end
if header then
header = false
end
end
output = output .. '\n|}'
return output
end
return p