Module:AbilityTable: Difference between revisions

Vergir (talk | contribs)
m Vergir moved page Module:AbilityTables to Module:AbilityTable: Misspelled title
Vergir (talk | contribs)
Rename abilityPropTable to render; add hide parameter for column hiding (with help from vergir-bot LLM)
Line 159: Line 159:
-- ============================================================
-- ============================================================


function p.abilityPropTable(frame)
function p.render(frame)
     local stat = mw.text.trim(frame.args[1] or ""):lower()
     local stat = mw.text.trim(frame.args[1] or ""):lower()


Line 165: Line 165:
     if not internal_keys then
     if not internal_keys then
         return '<span class="error">AbilityTable: unknown stat "' .. stat .. '".</span>'
         return '<span class="error">AbilityTable: unknown stat "' .. stat .. '".</span>'
    end
    -- Build set of columns to hide from the "hide" parameter
    local hide_set = {}
    local hide_param = mw.text.trim(frame.args["hide"] or "")
    if hide_param ~= "" then
        for col in hide_param:gmatch("[^,]+") do
            hide_set[mw.text.trim(col)] = true
        end
     end
     end


Line 198: Line 207:
     end)
     end)


     -- Determine final header list. "Notes" is included if declared in headers
     -- Determine final header list, respecting hide_set.
    -- (meaning the renderer may produce notes) or if human notes exist for
    -- "Notes" is included if declared in headers or if human notes exist,
     -- this stat. Either way it appears exactly once at the end.
     -- but only if not hidden. Either way it appears exactly once at the end.
     local has_notes_header = false
     local has_notes_header = false
     local final_headers = {}
     local final_headers = {}
Line 206: Line 215:
         if h == "Notes" then
         if h == "Notes" then
             has_notes_header = true
             has_notes_header = true
         else
         elseif not hide_set[h] then
             table.insert(final_headers, h)
             table.insert(final_headers, h)
         end
         end
     end
     end
     local needs_notes = has_notes_header or stat_notes ~= nil
     local needs_notes = (has_notes_header or stat_notes ~= nil) and not hide_set["Notes"]
     if needs_notes then
     if needs_notes then
         table.insert(final_headers, "Notes")
         table.insert(final_headers, "Notes")
Line 216: Line 225:


     -- Disclaimer
     -- Disclaimer
     local edit_url = mw.uri.fullUrl("Module:AbilityTables", { action = "edit" })
     local edit_url = mw.uri.fullUrl("Module:AbilityTable", { action = "edit" })
     local disclaimer = frame:preprocess(
     local disclaimer = frame:preprocess(
         '<div class="ability-table-disclaimer">'
         '<div class="ability-table-disclaimer">'