No edit summary |
No edit summary |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local IB_NIL = require('Module:InfoboxBuilderNil') |
|||
local Functions = {} |
local Functions = {} |
||
function Functions. |
function Functions.image(imageSize) |
||
return function(imageName) |
return function(imageName) |
||
if imageName == nil or imageName |
if imageName == nil or mw.text.trim(imageName) == '' then |
||
return nil |
|||
end |
|||
return string.format('[[File:%s|%s]]', imageName, imageSize) |
return string.format('[[File:%s|%s]]', imageName, imageSize) |
||
Line 10: | Line 11: | ||
end |
end |
||
function Functions. |
function Functions.link(pageName) |
||
if pageName == nil |
if pageName == nil or pageName == '' then return nil end |
||
return string.format('[[%s]]', pageName) |
return string.format('[[%s]]', pageName) |
||
end |
end |
||
function Functions. |
function Functions.list(listType) |
||
return function(array) |
return function(array) |
||
if array == nil |
if array == nil then return nil end |
||
local List = require('Module:List') |
local List = require('Module:List') |
||
Line 26: | Line 27: | ||
return List.renderList(data) |
return List.renderList(data) |
||
end |
end |
||
end |
|||
function Functions.trueFalseOther(trueVal, falseVal, otherVal) |
|||
return function(val) |
|||
-- probably should not use == with bool, but this is more explicit |
|||
if val == true then |
|||
return trueVal |
|||
elseif val == false then |
|||
return falseVal |
|||
end |
|||
return otherVal |
|||
end |
|||
end |
|||
function Functions.yesAndNo(val) |
|||
return Functions.trueFalseOther('Yes', 'No', nil)(val) |
|||
end |
|||
function Functions.checkAndX(val) |
|||
return Functions.trueFalseOther('✓', '✗', nil)(val) |
|||
end |
|||
function Functions.pluralHeader(forms) |
|||
local contentLang = mw.getContentLanguage() |
|||
return function(list) |
|||
return contentLang:convertPlural(#(list or {}), forms) |
|||
end |
|||
end |
|||
function Functions.minutesAndSeconds(seconds) |
|||
if seconds == nil then return nil end |
|||
return string.format( |
|||
'%d:%02d', |
|||
math.floor(seconds / 60), |
|||
math.floor(seconds % 60) |
|||
) |
|||
end |
end |
||
Latest revision as of 01:59, 29 April 2023
This module depends on the following other modules: |
This module contains several display helper functions for the Module:InfoboxBuilder and Module:DatatableBuilder. The only dependency this module has is Module:List; this is required to use list(listType)
and is only loaded when needed.
Functions[edit source]
image[edit source]
DisplayFunctions.image(imageSize)
Pass the desired image size as a parameter when setting it as the display function for a row. When called, this function will return a function that uses the first parameter as the filename.
link[edit source]
DisplayFunctions.link
When called, this function will use the first parameter as the link.
list[edit source]
DisplayFunctions.list(listType)
Pass the desired type of list as a parameter when setting it as the display function for a row. When called, this function will return a function that turns an array into a list.
Valid list types are:
- bulleted
- unbulleted
- horizontal
- ordered
- horizontal_ordered
Examples of these lists can be found on Wikipedia's documentation for Module:List.
trueFalseOther[edit source]
DisplayFunctions.trueFalseOther(trueVal, falseVal, otherVal)
Pass the true value, false value, and value if other as parameters when setting it as the display function for a row. When called, this function will return a function that takes a boolean value and returns the corresponding true, false, or other value.
yesAndNo[edit source]
DisplayFunctions.yesAndNo
When called, this function will display "Yes" for true
, "No" for false
, and nil
for everything else. This is a special case of trueFalseOther(trueVal, falseVal, otherVal)
.
checkAndX[edit source]
DisplayFunctions.checkAndX
When called, this function will display "✓" for true
, "✗" for false
, and nil
for everything else. This is a special case of trueFalseOther(trueVal, falseVal, otherVal)
.
pluralHeader[edit source]
DisplayFunctions.pluralHeader(forms)
Pass in a table of grammatical forms (see MediaWiki's documentation on the correct format) as the parameter when setting it as the display function for a row. When called, this function will return a function that selects the correct plurality based on the array passed in as parameter.
minutesAndSeconds[edit source]
DisplayFunctions.minutesAndSeconds
When called, this function will format a number (assumed to be seconds) into the "m:ss" format.
local Functions = {}
function Functions.image(imageSize)
return function(imageName)
if imageName == nil or mw.text.trim(imageName) == '' then
return nil
end
return string.format('[[File:%s|%s]]', imageName, imageSize)
end
end
function Functions.link(pageName)
if pageName == nil or pageName == '' then return nil end
return string.format('[[%s]]', pageName)
end
function Functions.list(listType)
return function(array)
if array == nil then return nil end
local List = require('Module:List')
local data = List.makeListData(listType, array)
return List.renderList(data)
end
end
function Functions.trueFalseOther(trueVal, falseVal, otherVal)
return function(val)
-- probably should not use == with bool, but this is more explicit
if val == true then
return trueVal
elseif val == false then
return falseVal
end
return otherVal
end
end
function Functions.yesAndNo(val)
return Functions.trueFalseOther('Yes', 'No', nil)(val)
end
function Functions.checkAndX(val)
return Functions.trueFalseOther('✓', '✗', nil)(val)
end
function Functions.pluralHeader(forms)
local contentLang = mw.getContentLanguage()
return function(list)
return contentLang:convertPlural(#(list or {}), forms)
end
end
function Functions.minutesAndSeconds(seconds)
if seconds == nil then return nil end
return string.format(
'%d:%02d',
math.floor(seconds / 60),
math.floor(seconds % 60)
)
end
return Functions