יחידה:תכונות טבלה

מתוך ויקיפדיה, האנציקלופדיה החופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:תכונות טבלה/תיעוד

local function param_to_class(param, val)
	local map = {
		['הסתרה'] = 'mw-collapsible mw-collapsed',
		['מיון'] = 'sortable',
		['סירוגין'] = 'ctd-oddgrey',
		['ריחוף'] = 'ctd-hover',
		['קיבוע כותרות']  = 'ctd-stickytableheader',
	}
	if map[param] then return map[param] end
	if param == 'classes' then return val end

	local features = {
		['שמאל'] = 'left',
		['מרכוז'] = 'center',
		['הדגשה'] = 'bold',
		['ללא שבירה'] = 'nowrap',
		['מרכוז משמאל'] = 'center-ltr',
	}
	for feature, code in pairs(features) do
		if param == 'עמודות ' .. feature then
			local cols, tab = mw.text.split(val, '%s*,%s*'), {}
			for _, col in ipairs(cols) do table.insert(tab, mw.ustring.format('ctd-%s-%s', code, col)) end
			return table.concat(tab, ' ')
		end
	end
	return ''
end



local function params_to_classes(args) 
	local classes = {}
	for param, val in pairs(args) do
		table.insert(classes, param_to_class(param, val))
	end
	return  'class="' ..  table.concat(classes, ' ') .. '"'
end

local function classes(frame)
	local args = {} -- collect arguments from the template, then the usage, so the template can set default values, and the usage can override
	for name, val in pairs(frame.args) do args[name] = val end
	for name, val in pairs(frame:getParent().args) do args[name] = val end
	return params_to_classes(args)
end

return {
	['תכונות'] = classes,
}