Module:Test2: Difference between revisions
From Elwiki
No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
-- Collect arguments from the old table. | |||
local input_args = split(mw.text.unstrip(args.orig), '|') | local input_args = split(mw.text.unstrip(args.orig), '|') | ||
local old_args = {} | local old_args = {} | ||
Line 18: | Line 19: | ||
args.orig = nil | args.orig = nil | ||
local new_args = table.deep_copy(old_args) | local new_args = table.deep_copy(old_args) | ||
for k, v in pairs( | -- Apply the new values to the new table. | ||
if | for k, v in pairs(args) do | ||
new_args[k] = | if args[k] then | ||
new_args[k] = args[k] | |||
end | end | ||
end | end | ||
for k, v in pairs( | -- Remove the values requested in the new table. | ||
if args | for k, v in pairs(old_args) do | ||
new_args[k] = | if indexOf(k, split(args.remove)) then | ||
new_args[k] = nil | |||
end | end | ||
end | end | ||
Line 37: | Line 39: | ||
end | end | ||
-- Finally, display the tabs. | |||
local old_table = frame:expandTemplate{ | local old_table = frame:expandTemplate{ | ||
title = 'Damage', | title = 'Damage', |
Revision as of 22:06, 25 April 2023
Documentation for this module may be created at Module:Test2/doc
require('Module:CommonFunctions');
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.Patch(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_arg[2]
end
end
args.orig = nil
local new_args = table.deep_copy(old_args)
-- Apply the new values to the new table.
for k, v in pairs(args) do
if args[k] 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 kr_date = 'KR (' .. args.date .. ')'
local tabber = frame:expandTemplate{
title = 'Tabber',
args = {
NA = old_table,
['$divclass'] = 'tabber-border',
['$divstyle'] = 'display: inline-flex',
[kr_date] = new_table
}
}
return tabber
end
return p