Module:DamagePatch: Difference between revisions
From Elwiki
(Created page with "require('Module:CommonFunctions'); local getArgs = require('Module:Arguments').getArgs local p = {} function p.main(frame) local args = getArgs(frame) -- Collect arguments from the old table. local input_args = split(mw.text.unstrip(args.orig), '|') local old_args = {} for k, v in ipairs(input_args) do local old_arg = split(v, '=') if not old_arg[2] then old_args[k] = v else old_args[old_arg[1]] = old_...") |
(Fix an issue where tabs were displayed in a wrong order) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
-- Collect arguments from the old table. | -- Collect arguments from the old table. | ||
local input_args = split(mw.text.unstrip(args | local input_args = split(mw.text.unstrip(args[1]), '|') | ||
local old_args = {} | local old_args = {} | ||
for k, v in ipairs(input_args) do | for k, v in ipairs(input_args) do | ||
Line 18: | Line 18: | ||
end | end | ||
args | args[1] = nil | ||
local new_args = table.deep_copy(old_args) | local new_args = table.deep_copy(old_args) | ||
Line 50: | Line 50: | ||
args = new_args | args = new_args | ||
} | } | ||
local old_content = mw.html.create('div') | |||
:tag('div'):wikitext(old_table) | |||
if args.old then | |||
old_content:tag('div'):wikitext(frame:preprocess(string.char(10) .. args.old)) | |||
end | |||
local new_content = mw.html.create('div') | |||
:tag('div'):wikitext(new_table) | |||
if args.new or args.old then | |||
new_content:tag('div'):wikitext(frame:preprocess(string.char(10) .. (args.new or args.old))) | |||
end | |||
local kr_date = 'KR (' .. args.date .. ')' | local kr_date = 'KR (' .. args.date .. ')' | ||
local tabber = frame: | local tabber = frame:preprocess("<tabber>\\\\NA=".. tostring(old_content) .."\\\\".. kr_date .."=".. tostring(new_content) .."</tabber>") | ||
return tabber | return tabber |
Latest revision as of 23:38, 18 April 2024
Documentation for this module may be created at Module:DamagePatch/doc
require('Module:CommonFunctions');
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
-- Collect arguments from the old table.
local input_args = split(mw.text.unstrip(args[1]), '|')
local old_args = {}
for k, v in ipairs(input_args) do
local old_arg = split(v, '=')
if not old_arg[2] then
old_args[k] = v
else
old_args[old_arg[1]] = old_arg[2]
end
end
args[1] = nil
local new_args = table.deep_copy(old_args)
local exclude_args = {'date', 'remove'}
-- Apply the new values to the new table.
for k, v in pairs(args) do
if args[k] and not indexOf(k, exclude_args) then
new_args[k] = args[k]
end
end
-- Remove the values requested in the new table.
for k, v in pairs(old_args) do
if indexOf(k, split(args.remove)) then
new_args[k] = nil
end
end
if args.dump then
return inspect_dump(frame, new_args)
end
-- Finally, display the tabs.
local old_table = frame:expandTemplate{
title = 'Damage',
args = old_args
}
local new_table = frame:expandTemplate{
title = 'Damage',
args = new_args
}
local old_content = mw.html.create('div')
:tag('div'):wikitext(old_table)
if args.old then
old_content:tag('div'):wikitext(frame:preprocess(string.char(10) .. args.old))
end
local new_content = mw.html.create('div')
:tag('div'):wikitext(new_table)
if args.new or args.old then
new_content:tag('div'):wikitext(frame:preprocess(string.char(10) .. (args.new or args.old)))
end
local kr_date = 'KR (' .. args.date .. ')'
local tabber = frame:preprocess("<tabber>\\\\NA=".. tostring(old_content) .."\\\\".. kr_date .."=".. tostring(new_content) .."</tabber>")
return tabber
end
return p