Module:Abilities/utils: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
added format_value_with_prepost |
||
| Line 17: | Line 17: | ||
end | end | ||
return nil | return nil | ||
end | |||
-- Add prefix and postfix labels to a value. Eg. "32" -> "32s" | |||
function format_value_with_prepost(key, value, frame) | |||
if (value == nil) then return nil end | |||
local prefix = lang._get_string(string.format("%s_prefix",key)) | |||
local postfix = lang._get_string(string.format("%s_postfix",key)) | |||
-- Default pre/post fix to empty string, as they may not exist | |||
if (prefix == nil) then prefix = '' end | |||
if (postfix == nil) then postfix = '' end | |||
-- If string ends with 'm', then set the postfix to 'm' and remove it | |||
if utils.string_endswith(tostring(value), 'm') then | |||
value = tonumber(value:sub(1, -2)) | |||
postfix = 'm' | |||
end | |||
if (prefix == '{s:sign}') then | |||
if value < 0 then | |||
prefix = '-' | |||
else | |||
prefix = '+' | |||
end | |||
-- if no prefix on positive value, add a '+' | |||
else | |||
if value > 0 then | |||
prefix = '+' | |||
end | |||
end | |||
value_and_uom = frame:expandTemplate{ | |||
title = 'Template:ValueAndUom', | |||
args = { | |||
prefix..value, | |||
postfix, | |||
uom_style = 'font-size: 12px;' | |||
} | |||
} | |||
return value_and_uom | |||
end | end | ||
return p | return p | ||