Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:ESTable: Difference between revisions

From Teriock
Content deleted Content added
// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Tag: Reverted
Line 96: Line 96:
-- Data rows
-- Data rows
for _, row in ipairs(data) do
-- for _, row in ipairs(data) do
if (#row > 0) and (#selectedCols > 0) then
-- if (#row > 0) and (#selectedCols > 0) then
output = output .. '|-\n\n| '
-- output = output .. '|-\n\n| '
for _, col in ipairs(selectedCols) do
-- for _, col in ipairs(selectedCols) do
output = output .. ' || ' .. row[col.index]
-- output = output .. ' || ' .. row[col.index]
end
-- end
output = output .. '\n'
-- output = output .. '\n'
end
-- end
end
-- end
output = output .. '|}'
output = output .. '|}'

Revision as of 19:11, 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
}

-- 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

    -- 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
    -- for _, row in ipairs(data) do
    --     if (#row > 0) and (#selectedCols > 0) then
    --         output = output .. '|-\n\n| '
    --         for _, col in ipairs(selectedCols) do
    --             output = output .. ' || ' .. row[col.index]
    --         end
    --         output = output .. '\n'
    --     end
    -- end
    
    output = output .. '|}'
    return output
end

return p