Modul:Infobox: Skillnad mellan sidversioner
mIngen redigeringssammanfattning |
Lade till en funktion för vikt, under konstruktion |
||
| (5 mellanliggande sidversioner av samma användare visas inte) | |||
| Rad 38: | Rad 38: | ||
end | end | ||
return table.concat(output, ' · ') | return table.concat(output, ' · ') | ||
end | |||
function p.moralAlignment( frame ) | |||
local output = {} | |||
local value = frame.args[1] | |||
local value2 = frame.args[2] | |||
local alignment = { | |||
['ond'] = f.categoryLink( 'Onda figurer', vars.Pagename, 'Ond' ), | |||
['neutral'] = f.categoryLink( 'Neutrala figurer', vars.Pagename, 'Neutral' ), | |||
['god'] = f.categoryLink( 'Goda figurer', vars.Pagename, 'God' ), | |||
} | |||
if alignment[string.lower(value)] then | |||
output = alignment[string.lower(value)] | |||
elseif mw.site.stats.pagesInCategory( | |||
f.firstToUpper(value) .. 'a figurer', 'pages' | |||
) > 0 then | |||
output = f.categoryLink( | |||
f.firstToUpper(value) .. 'a figurer', vars.Pagemane, value | |||
) | |||
else | |||
output = value | |||
end | |||
if value2 then | |||
return output .. ', ' .. value2 | |||
else | |||
return output | |||
end | |||
end | end | ||
| Rad 72: | Rad 99: | ||
table.insert(output, frame.args[2]) | table.insert(output, frame.args[2]) | ||
return table.concat(output, ' ') | return table.concat(output, ' ') | ||
end | |||
function p.weight( frame ) | |||
local value = frame.args['vikt'] or frame.args[1] | |||
local value2 = frame.args['vikt2'] or frame.args[2] or '' | |||
local output = '' | |||
local units = { | |||
['lbs'] = { | |||
['lbs'] = 1.0, | |||
['kg'] = 0.453592, | |||
['ton'] = 0.00045 | |||
}, | |||
['kg'] = { | |||
['lbs'] = 2.20462, | |||
['kg'] = 1.0, | |||
['ton'] = 0.001 | |||
}, | |||
['ton'] = { | |||
['lbs'] = 2204.62, | |||
['kg'] = 1000.0, | |||
['ton'] = 1.0 | |||
} | |||
} | |||
local unit = '' | |||
if string.find(value, 'kg') or string.find(value, 'kilo') then | |||
unit = 'kg' | |||
elseif string.find(value, 'ton') then | |||
unit = 'ton' | |||
elseif string.find(value, 'lbs') then | |||
unit = 'lbs' | |||
else | |||
unit = '' | |||
end | |||
if unit ~= '' then | |||
local weight = tonumber( string.match(value, '%d+') ) | |||
local weightKg = f.round( weight * units[unit].kg , 0 ) | |||
local weightLbs = f.round( weight * units[unit].lbs , 0 ) | |||
local validWeight = weightKg .. ' kg (' .. weightLbs .. ' lbs)' | |||
output = validWeight | |||
if not f.isEmpty(value2) then | |||
output = output .. ' ' .. value2 | |||
end | |||
else | |||
if f.isEmpty(value2) then | |||
output = value | |||
else | |||
output = value .. ' ' .. value2 | |||
end | |||
end | |||
return output | |||
end | end | ||
return p | return p | ||
Nuvarande version från 1 november 2023 kl. 11.28
Dokumentationen för denna modul kan skapas på Modul:Infobox/dok
Skriptfel: Luafel: Internt fel: Tolken har avslutats med signalen "11".
local p = {}
_G.vars = { Pagename = mw.title.getCurrentTitle().text }
local f = require("Modul:Funktioner")
function p.birthdate(frame)
local date = frame.args['date'] or frame.args[1]
local date_lc = string.lower(date)
if string.match(date_lc, "okänt") or string.match(date_lc, "okänd") then
return "[[:Kategori:Figurer med okänt födelsedatum|" .. date .. "]][[Kategori:Figurer med okänt födelsedatum]]"
elseif string.match(date_lc, "ej fastställd") or string.match(date_lc, "ej fastställt") or string.match(date_lc, "inte fastställd") or string.match(date_lc, "inte fastställt") then
return "[[:Kategori:Figurer utan fastställt födelsedatum|" .. date .. "]][[Kategori:Figurer utan fastställt födelsedatum]]"
else
return "[[" .. date .. "]]"
end
end
function p.affiliation( frame )
local text = frame.args['text'] or frame.args[1] or nil
local delimiter = frame.args['delimiter'] or frame.args[2] or ';'
local affiliates = mw.text.split( text, delimiter )
local output = {}
for i, item in ipairs( affiliates ) do
item = f.trim(item)
if not string.match(item, '%S') then break end
if string.lower(item) == "nordens stjärnor" or string.lower(item) == "nordens stjÄrnor" then
item = "[[Nordens Stjärnor]][[Kategori:Medlemmar i Nordens Stjärnor]]"
else
item = "[[" .. item .. "]]"
end
table.insert(output, item)
end
return table.concat(output, ' · ')
end
function p.moralAlignment( frame )
local output = {}
local value = frame.args[1]
local value2 = frame.args[2]
local alignment = {
['ond'] = f.categoryLink( 'Onda figurer', vars.Pagename, 'Ond' ),
['neutral'] = f.categoryLink( 'Neutrala figurer', vars.Pagename, 'Neutral' ),
['god'] = f.categoryLink( 'Goda figurer', vars.Pagename, 'God' ),
}
if alignment[string.lower(value)] then
output = alignment[string.lower(value)]
elseif mw.site.stats.pagesInCategory(
f.firstToUpper(value) .. 'a figurer', 'pages'
) > 0 then
output = f.categoryLink(
f.firstToUpper(value) .. 'a figurer', vars.Pagemane, value
)
else
output = value
end
if value2 then
return output .. ', ' .. value2
else
return output
end
end
function p.maritalStatus( frame )
local statuses = mw.text.split( frame.args[1], ';')
local output = {}
for i, status in ipairs( statuses ) do
if string.lower(status) == "gift"
or string.lower(status) == "omgift"
or string.lower(status) == "nygift" then
table.insert( output, f.categoryLink( "Gifta figurer", vars.Pagename, status ) )
elseif string.lower(status) == "i förhållande"
or string.lower(status) == "förhållande" then
table.insert( output, f.categoryLink( "Figurer i förhållande", vars.Pagename, status ) )
elseif string.lower(status) == "änka"
or string.lower(status) == "änkling"
or string.lower(status) == "änkeman"
or string.lower(status) == "Änka"
or string.lower(status) == "Änkling"
or string.lower(status) == "Änkeman" then
table.insert( output, f.categoryLink( "Änkestående figurer", vars.Pagename, status ) )
elseif string.lower(status) == "singel"
or string.lower(status) == "ogift"
or string.lower(status) == "ensamstående" then
table.insert( output, f.categoryLink( "Ensamstående figurer", vars.Pagename, status ) )
elseif string.lower(status) == "förlovade" then
table.insert( output, f.categoryLink( "Förlovade figurer", vars.Pagename, status ) )
else
table.insert( output, f.categoryLink( status .. "a figurer", vars.Pagename, status ) )
end
end
table.insert(output, frame.args[2])
return table.concat(output, ' ')
end
function p.weight( frame )
local value = frame.args['vikt'] or frame.args[1]
local value2 = frame.args['vikt2'] or frame.args[2] or ''
local output = ''
local units = {
['lbs'] = {
['lbs'] = 1.0,
['kg'] = 0.453592,
['ton'] = 0.00045
},
['kg'] = {
['lbs'] = 2.20462,
['kg'] = 1.0,
['ton'] = 0.001
},
['ton'] = {
['lbs'] = 2204.62,
['kg'] = 1000.0,
['ton'] = 1.0
}
}
local unit = ''
if string.find(value, 'kg') or string.find(value, 'kilo') then
unit = 'kg'
elseif string.find(value, 'ton') then
unit = 'ton'
elseif string.find(value, 'lbs') then
unit = 'lbs'
else
unit = ''
end
if unit ~= '' then
local weight = tonumber( string.match(value, '%d+') )
local weightKg = f.round( weight * units[unit].kg , 0 )
local weightLbs = f.round( weight * units[unit].lbs , 0 )
local validWeight = weightKg .. ' kg (' .. weightLbs .. ' lbs)'
output = validWeight
if not f.isEmpty(value2) then
output = output .. ' ' .. value2
end
else
if f.isEmpty(value2) then
output = value
else
output = value .. ' ' .. value2
end
end
return output
end
return p