Jump to content

Module:Create style property settings

Permanently protected module
From Wikipedia, the free encyclopedia
local me = { }

function me.fromMapping(frame)
	local outputBuffer = { }
	local parentFrame = frame:getParent()
	for templateArgName, cssPropertyName in pairs(frame.args) do
		local cssValue = parentFrame.args[templateArgName]
		if cssValue ~= nil then
			table.insert(outputBuffer, cssPropertyName .. ': ' .. cssValue .. ';')
		end
	end

	-- if table is empty, concat will return an empty string
	return table.concat(outputBuffer, ' ')
end  -- function me.fromMapping()

function me.fromMappingForFlexboxWrap(frame)
	local outputBuffer = { }
	local parentFrame = frame:getParent()
	for templateArgName, cssPropertyName in pairs(frame.args) do
		local cssValue = parentFrame.args[templateArgName]
		local generateStyle = cssValue ~= nil
		if (templateArgName == 'flex')
			and not ((cssValue == nil) or (cssValue == 'none') or string.match(cssValue, '^%s*%d+%s*$')) then
			generateStyle = false
		end
		if generateStyle then
			table.insert(outputBuffer, cssPropertyName .. ': ' .. cssValue .. ';')
		end
	end

	-- if table is empty, concat will return an empty string
	return table.concat(outputBuffer, ' ')
end  -- function me.fromMappingForFlexboxWrap

return me