Module:columns/auto

From Linguifex
< Module:columns
Revision as of 15:29, 11 September 2023 by Sware (talk | contribs) (Created page with "local export = {} function export.decide_number_of_columns(lang, number_of_items) if number_of_items <= 3 then return 1 elseif number_of_items <= 9 then return 2 elseif number_of_items <= 27 then return 3 elseif number_of_items <= 81 then return 4 else return 5 end end function export.display_from(column_args, list_args) if not column_args["columns"] then local m_table = require("Module:table") column_args = m_table.shallowcopy(column_args) local...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:columns/auto/doc

local export = {}

function export.decide_number_of_columns(lang, number_of_items)
	if number_of_items <= 3 then
		return 1
	elseif number_of_items <= 9 then
		return 2
	elseif number_of_items <= 27 then
		return 3
	elseif number_of_items <= 81 then
		return 4
	else
		return 5
	end
end

function export.display_from(column_args, list_args)
	if not column_args["columns"] then
		local m_table = require("Module:table")
		column_args = m_table.shallowcopy(column_args)
		local lang = require("Module:languages").getByCode(mw.text.trim(list_args[1]), 1)
		column_args["columns"] = export.decide_number_of_columns(lang, m_table.length(list_args))
	end
	return require("Module:columns").display_from(column_args, list_args)
end

function export.display(frame)
	return export.display_from(frame.args, frame:getParent().args)
end

return export