Module:Module sandbox: Difference between revisions
Content deleted Content added
Undid revision 1218974955 by Thisasia (talk) |
No edit summary Tags: Reverted Mobile edit Mobile web edit Advanced mobile edit |
||
Line 5: | Line 5: | ||
local function cmToFeetAndInches(cm) |
local function cmToFeetAndInches(cm) |
||
local cmValue = tonumber(cm:match("%d+")) |
|||
if cmValue then |
|||
local totalInches = cmValue / 2.54 |
|||
local feet = math.floor(totalInches / 12) |
|||
local inches = math.floor(totalInches % 12) |
|||
return string.format("%d cm (%d feet %d inches)", cmValue, feet, inches) |
|||
⚫ | |||
return "Invalid input" |
|||
end |
end |
||
local function kgToPounds(kg) |
local function kgToPounds(kg) |
||
local kgValue = tonumber(kg:match("%d+")) |
|||
if kgValue then |
|||
local pounds = kgValue * 2.20462 |
|||
return string.format("%d kg (%.2f pounds)", kgValue, pounds) |
|||
end |
|||
return "Invalid input" |
|||
end |
end |
||
Line 29: | Line 15: | ||
local firstDescriptionFound = false |
local firstDescriptionFound = false |
||
local cmProcessed = false |
local cmProcessed = false |
||
for key, value in pairs(args) do |
for key, value in pairs(args) do |
||
if key |
if key == 'image' then |
||
if value ~= "" then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if value ~= "" then |
if value ~= "" then |
||
output = output .. '| style="font-size:20px;text-align: center; background-color: ' .. (args.headcolor or "#f2f2f2") .. '; color: ' .. (args.color or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n' |
output = output .. '| style="font-size:20px;text-align: center; background-color: ' .. (args.headcolor or "#f2f2f2") .. '; color: ' .. (args.color or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n' |
||
firstDescriptionFound = true |
firstDescriptionFound = true |
||
end |
end |
||
elseif key == 'caption' then |
|||
if value ~= "" then |
|||
end |
|||
output = output .. '|<small style="display: block; text-align: center;">' .. value .. '</small>\n|-\n' |
|||
end |
|||
elseif key:sub(1, 3) == 'abv' then |
|||
local imagesize = args.imagesize or "" |
|||
⚫ | |||
end |
|||
for key, value in pairs(args) do |
|||
⚫ | |||
if value ~= "" then |
if value ~= "" then |
||
output = output .. '| |
output = output .. '| <b>abv</b>\n| ' .. value .. '\n|-\n' |
||
end |
end |
||
elseif key ~= 'image' and |
elseif key ~= 'image' and not key:find('^abv') and key ~= 'up' and key ~= 'caption' then |
||
if |
if value ~= '' then |
||
local convertedValue = value |
local convertedValue = value |
||
if type(value) == "string" then |
if type(value) == "string" then |
Revision as of 00:47, 15 April 2024
Welcome to Module:Module sandbox, a Wikipedia module sandbox. This page is itself a module, and it allows you to carry out experiments related to module editing. If you wish to experiment with article editing, use the Wikipedia Sandbox or your own user sandbox.
To edit, click the edit tab above, make your changes and click the Publish changes button when finished. Please do not place malicious Lua code here, or copyrighted, offensive, illegal or libelous content in the sandboxes. For assistance with Lua coding, try the technical forum at the Village Pump. There are also several template sandboxes you can use to carry out experiments:
You can also conduct tests using the Wikipedia Sandbox. For instance, to invoke this module there, edit it so that it includes: {{#invoke:Module sandbox}} |
More info
Sandbox games |
Usage
{{#invoke:Module sandbox|function_name}}
local p = {}
local function calculateAge(dateOfBirth)
end
local function cmToFeetAndInches(cm)
end
local function kgToPounds(kg)
end
function p.infobox(frame)
local args = frame:getParent().args
local output = '{| class="infobox biography vcard" style="width: 22em;"\n'
local firstDescriptionFound = false
local cmProcessed = false
for key, value in pairs(args) do
if key == 'image' then
if value ~= "" then
output = output .. '|' ..'<div style="text-align:center;">'.. value .. '</div>\n|-\n'
end
elseif key == 'up' then
if value ~= "" then
output = output .. '| style="font-size:20px;text-align: center; background-color: ' .. (args.headcolor or "#f2f2f2") .. '; color: ' .. (args.color or "inherit") .. '; font-weight: bold;" | ' .. value .. '\n|-\n'
firstDescriptionFound = true
end
elseif key == 'caption' then
if value ~= "" then
output = output .. '|<small style="display: block; text-align: center;">' .. value .. '</small>\n|-\n'
end
elseif key:sub(1, 3) == 'abv' then
if value ~= "" then
output = output .. '| <b>abv</b>\n| ' .. value .. '\n|-\n'
end
elseif key ~= 'image' and not key:find('^abv') and key ~= 'up' and key ~= 'caption' then
if value ~= '' then
local convertedValue = value
if type(value) == "string" then
if value:match("%s*cm%s*") then
convertedValue = cmToFeetAndInches(value)
cmProcessed = true
elseif value:match("%s*kg%s*") or value:match("%s*kgs%s*") then
if cmProcessed then
convertedValue = '\n' .. kgToPounds(value)
else
convertedValue = kgToPounds(value)
end
end
elseif type(value) == "number" then
local age = calculateAge(tostring(value))
if age then
convertedValue = tostring(value) .. ' (' .. age .. ' years old)'
end
end
output = output .. '| <b>' .. key .. '</b>\n| ' .. tostring(convertedValue) .. '\n|-\n'
end
end
end
output = output .. '|}\n'
return output
end
return p