-- Testmodule to generate the international goals by <
function p.hello(frame) -- Declare locals local Args = getArgs(frame,) local final_result = local index = 0 local goals_count = 0 local entries_list = -- Temp check for testcases if (Args["test"] ~= nil) then return "No parameters found." end -- Temp check for data groups if (Args["data5"] ~= nil) then mw.log("data group = " .. type(Args["data5"])) end --Get all the entries in nested table, index start at 1 while (Args["date"..index+1] ~= nil) do index = index+1 entries_list[index] = end mw.logObject(entries_list) --Only 1 header local header = p.get_header(frame, Args) table.insert(final_result, string.format("%s", header)) --Only 1 type/gender local type = string.lower(Args["type"]) index = 0 while (entries_list[index+1] ~= nil) do index = index+1 --increment goals goals_count = goals_count + 1 --Add date col local date_col = frame:expandTemplate --Add venue col+check if wikilink format is needed (default yes) local venue_col = p.check_wikilink --Add opponent col (check type/gender) local opp_col = nil switch(type,) --Add scores -> determines if/how many rowspan is needed local scores = mw.text.split(entries_list[index]["scores"], ",") local rowspan = #scores --check home/away for scores, default home=yes; format accordingly -> player goals = bold local is_home = yesno(entries_list[index]["home"] or "yes") and true or false --Add result local result_col = p.format_score(mw.text.split(entries_list[index]["result"], "-"), is_home) --Add competition local comp_col = nil if (entries_list[index]["comp_alt"] ~= nil) then comp_col = string.format("%s", entries_list[index]["comp"], entries_list[index]["comp_alt"]) else comp_col = string.format("%s", entries_list[index]["comp"]) end --Add references (cite_web) local ref_col = p.format_ref(frame, entries_list[index]["ref"], index) --Put all in rows. If rowspan > 1 means that multiple scorelines have to be 'rowspanned' if (rowspan > 1) then score_col = p.format_score(mw.text.split(scores[1], "-"), is_home) --Treat 1st row as regular single row local single_row = p.get_single_row(rowspan) table.insert(final_result, string.format("\n|-\n%s", single_row)) --loop over remaining scores, remove the 1st one table.remove(scores, 1) --mw.logObject(scores) --Add rest of the rowspanned rows for k,v in ipairs(scores) do --increment goals count goals_count = goals_count + 1 score_col = p.format_score(mw.text.split(v, "-"), is_home) local single_row2 = string.format("|style='text-align:center;'|%d||style='text-align:center;'|%s", goals_count, score_col) local rows = string.format("\n|-\n%s", single_row2) table.insert(final_result, rows) end else --no rowspan = only 1 score to format score_col = p.format_score(mw.text.split(scores[1], "-"), is_home) --Regular single row local single = p.get_single_row table.insert(final_result, string.format("\n|-\n%s", single)) end end table.insert(final_result, string.format("\n|-\n")) table.insert(final_result, string.format(frame:expandTemplate)) --mw.log("goals=" .. goals_count) mw.logObject(final_result) return table.concat(final_result)end
function p.get_header(frame, fields) local header = frame:expandTemplate local disclaimer = string.format(":Scores and results list %s's goal tally first, score column indicates score after each %s goal.", fields["name"], fields["name"]) return string.format("%s\n%s", disclaimer, header)end
-- Get single table row, with optional rowspanfunction p.get_single_row(fields, row_span) if (row_span ~= nil) then return string.format("|style='text-align:center;'|%d||rowspan=%d|%s||rowspan=%d|%s||rowspan=%d|%s||style='text-align:center;'|%s||rowspan=%d style='text-align:center;'|%s||rowspan=%d|%s||rowspan=%d|%s", fields["goals"], row_span, fields["date"], row_span, fields["venue"], row_span, fields["oppo"], fields["score"], row_span, fields["result"], row_span, fields["comp"], row_span, fields["ref"]) else return string.format("|style='text-align:center;'|%d||%s||%s||%s||style='text-align:center;'|%s||style='text-align:center;'|%s||%s||%s", fields["goals"], fields["date"], fields["venue"], fields["oppo"], fields["score"], fields["result"], fields["comp"], fields["ref"]) endend
-- Properly format score/result text (en dash) and inverse away goalsfunction p.format_score(scores, is_home) if (is_home) then return string.format("%s—%s", scores[1], scores[2]) else return string.format("%s—%s", scores[2], scores[1]) endend
-- Properly format referencesfunction p.format_ref(frame, field, index) -- Or: frame:expandTemplate return frame:expandTemplateend
-- Check if venue text needs to be wikilinkedfunction p.check_wikilink(fields) local add_link = yesno(fields["link"] or "yes") and true or false if (add_link) then return string.format("%s, %s, %s", fields["stadium"], fields["city"], fields["country"]) else return string.format("%s, %s, %s", fields["stadium"], fields["city"], fields["country"]) endend
-- Switch/case struct for types_G.switch = function(param, case_table) local case = case_table[param] if case then return case end local def = case_table['default'] return def and def or nilend
return p