Módulo:Número de estrelas

Revisão em 01h14min de 14 de maio de 2024 por Jaewoo (discussão | contribs) (Criou a página com "local p = {} function p._starnumber(num, maxnum) -- num of stats / maximal number of stars possible (shows grey stars for the difference) if not num then return nil end if not tonumber(num) then return num .. '(?)' -- error handling ? end num = tonumber(num) local maxnum = tonumber(maxnum) or num local starsize = '11px' if maxnum > 6 then starsize = '7px' end local str = '' local images = {...")
(dif) ← Revisão anterior | Revisão atual (dif) | Revisão seguinte → (dif)

A documentação para este módulo pode ser criada na página Módulo:Número de estrelas/doc

local p = {}
function p._starnumber(num, maxnum) -- num of stats / maximal number of stars possible (shows grey stars for the difference)
				if not num then
								return nil
				end
				if not tonumber(num) then
								return num .. '(?)' -- error handling ?
				end
				num = tonumber(num)
				local maxnum = tonumber(maxnum) or num
				local starsize = '11px'
				if maxnum > 6 then
								starsize = '7px'
				end
				
				local str = ''
				local images = {
								full = 'Star full.svg',
								half = 'Star half.svg',
								empty = 'Star empty.svg'
				}
				local function addstar(startype)
								str = str .. '[[File:' .. images[startype] .. '|' .. starsize .. ']]'
				end
				for i = 1, math.floor(num) do
								addstar('full')
				end
				
				if num > math.floor(num) then -- meia estrela
								addstar('half')
				end
				
				for i = 1, (maxnum - math.ceil(num)) do
								addstar('empty')
				end
				
				return  '<span style="white-space:nowrap">' .. str  .. '</span>'
end
function p.starnumber(frame)
				return p._starnumber(frame.args[1], frame.args[2])
end
return p