More actions
Content deleted Content added
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
Line 4: | Line 4: | ||
local columns = { |
local columns = { |
||
op = 1, |
op = 1, |
||
celestial_nouns = |
celestial_nouns = 2, |
||
celestial_verbs = |
celestial_verbs = 3, |
||
adjectives = |
adjectives = 4, |
||
adverbs = |
adverbs = 5, |
||
pronouns = |
pronouns = 6, |
||
propositions = |
propositions = 7, |
||
conjunctives = |
conjunctives = 8, |
||
articles = |
articles = 9, |
||
flame_verbs = |
flame_verbs = 10, |
||
flame_nouns = |
flame_nouns = 11, |
||
storm_verbs = |
storm_verbs = 12, |
||
storm_nouns = |
storm_nouns = 13, |
||
life_verbs = |
life_verbs = 14, |
||
life_nouns = |
life_nouns = 15, |
||
necro_verbs = |
necro_verbs = 16, |
||
necro_nouns = |
necro_nouns = 17, |
||
nature_verbs = |
nature_verbs = 18, |
||
nature_nouns = |
nature_nouns = 19 |
||
} |
} |
||
Revision as of 20:10, 23 January 2025
Documentation for this module may be created at Module:ESTable/doc
local p = {}
-- Column mappings
local columns = {
op = 1,
celestial_nouns = 2,
celestial_verbs = 3,
adjectives = 4,
adverbs = 5,
pronouns = 6,
propositions = 7,
conjunctives = 8,
articles = 9,
flame_verbs = 10,
flame_nouns = 11,
storm_verbs = 12,
storm_nouns = 13,
life_verbs = 14,
life_nouns = 15,
necro_verbs = 16,
necro_nouns = 17,
nature_verbs = 18,
nature_nouns = 19
}
local backgrounds = {
op = '#dc8add1A',
celestial_nouns = '#dc8add1A',
celestial_verbs = '#dc8add1A',
adjectives = '#dc8add1A',
adverbs = '#dc8add1A',
pronouns = '#dc8add1A',
propositions = '#dc8add1A',
conjunctives = '#dc8add1A',
articles = '#dc8add1A',
flame_verbs = '#f661511A',
flame_nouns = '#f661511A',
storm_verbs = '#99c1f11A',
storm_nouns = '#99c1f11A',
life_verbs = '#ffffff1A',
life_nouns = '#ffffff1A',
necro_verbs = '#77767b1A',
necro_nouns = '#77767b1A',
nature_verbs = '#8ff0a41A',
nature_nouns = '#8ff0a41A'
}
local backgrounds_even = {
op = '#6135831A',
celestial_nouns = '#6135831A',
celestial_verbs = '#6135831A',
adjectives = '#6135831A',
adverbs = '#6135831A',
pronouns = '#6135831A',
propositions = '#6135831A',
conjunctives = '#6135831A',
articles = '#6135831A',
flame_verbs = '#a51d2d1A',
flame_nouns = '#a51d2d1A',
storm_verbs = '#1a5fb41A',
storm_nouns = '#1a5fb41A',
life_verbs = '#9a99961A',
life_nouns = '#9a99961A',
necro_verbs = '#0000001A',
necro_nouns = '#0000001A',
nature_verbs = '#26a2691A',
nature_nouns = '#26a2691A'
}
-- 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
op = tonumber(row[1]) or 0
if bg then
if op % 2 == 0 then
content = content .. ' style="background-color: ' .. backgrounds_even[col.name] .. '" |'
else
content = content .. ' style="background-color: ' .. backgrounds[col.name] .. '" |'
end
-- 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