Module:Infobox/utilities
Appearance
This module is intended to be a repository for miscellaneous utility functions that support various infoboxes.
- for
{{Infobox U.S. congressional district}}
distribution_sort()
– sorts the various distribution parameters and renders an unbulleted list of sameethnicity_sort()
– sorts the various ethnicity parameters and renders an unbulleted list of sameoccupation_sort()
– sorts the various occupation parameters and renders an unbulleted list of same
- for
{{Infobox book}}
set_italics()
– used to ensure that book-titles in cjk scripts are not italicizedis_cjk_code()
– (private) returns true when language code represents a cjk language
require('Module:No globals');
local getArgs = require ('Module:Arguments').getArgs;
--[[--------------------------< C O M P >----------------------------------------------------------------------
compare function for result{} table descending sort
]]
local function comp (a, b)
return tonumber (a[1]) > tonumber (b[1]);
end
--[[--------------------------< E T H N I C I T Y _ S O R T >--------------------------------------------------
{{#invoke:Sandbox/trappist the monk/ethnicity sort|ethnicity_sort|{{{percent white|}}}|{{{percent black|}}}|{{{percent asian|}}}|{{{percent hispanic|}}}|{{{percent native american|}}}|{{{percent native hawaiian|}}}|{{{percent more than one race|}}}|{{{percent other race|}}} }}
]]
local function ethnicity_sort (frame)
local args=getArgs(frame);
local result = { -- initialize; table will be sorted according to values in result[n][1]
{args[1], '% [[White people|white]]'},
{args[2], '% [[Black people|black]]'},
{args[3], '% [[Asian Americans|Asian]]'},
{args[4], '% [[Hispanic]]'},
{args[5], '% [[Native Americans in the United States|Native American]]'},
{args[6], '% [[Pacific Islands Americans]]'},
{args[7], '% [[Two or more races]]'},
{args[8], '% other'},
};
for i=8, 1, -1 do
if not tonumber (result[i][1]) then -- if cannot be converted to a number
table.remove (result, i); -- delete
end
end
table.sort (result, comp); -- sort what remains
for i, v in ipairs (result) do
result[i] = table.concat (result[i]); -- make each table in result{} a string
end
result[1] = table.concat ({result[1], args[9] and args[9] or ''});
return frame:expandTemplate { title = 'Unbulleted list', args = result}; -- render the unbulleted list
end
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
]]
return {
ethnicity_sort = ethnicity_sort,
}