Module:Adaptable background

Revision as of 03:10, 22 April 2024 by R74n (talk | contribs) (Created page with "-- Code by Melecie (Q684) p = {} -- literally my first lua code ever please don't bite :3 -mel -- Function returns either a solid or gradient background depending on the number of inputs p.bg = function(frame) local length = 0 local colors = {} for i in string.gmatch(frame.args[1], "[^,]+") do table.insert(colors, i) length = length + 1 end if length > 1 then -- return gradient local background = "background-image: linear-gradient(to right" for n = 1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Adaptable background/doc

-- Code by Melecie (Q684)

p = {}

-- literally my first lua code ever please don't bite :3 -mel
-- Function returns either a solid or gradient background depending on the number of inputs
p.bg = function(frame)
	local length = 0
	local colors = {}

	for i in string.gmatch(frame.args[1], "[^,]+") do
		table.insert(colors, i)
		length = length + 1	
	end
	
	if length > 1 then
		-- return gradient
		local background = "background-image: linear-gradient(to right"
		for n = 1, length do
			background = background .. ", " .. colors[n]
		end
		background = background .. ");"
		mw.log(background)
		return background
	else
		-- return solid
		mw.log("background: " .. colors[1] .. ";")
		return "background: " .. colors[1] .. ";"
	end
end

return p