Siirry sisältöön

Moduuli:Singlet

Wikipediasta


Käyttöohje ja tekniset tiedot moduulille Singlet

Moduuli toteuttaa mallineen {{Singlet}}. Katso lisää mallineen ohjesivulta.


local p = {}

-- Ripped from Module:Infobox. TODO: Make a utility module that can do this kind of thing
local function getArgNums(args, prefix)
    -- Returns a table containing the numbers of the arguments that exist
    -- for the specified prefix. For example, if the prefix was 'data', and
    -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
    local nums = {}
    for k, v in pairs(args) do
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
        if num then table.insert(nums, tonumber(num)) end
    end
    table.sort(nums)
    return nums
end

function p.main(frame)
	local args = require('Moduuli:Arguments').getArgs(frame, {wrappers = 'Malline:Singlet'})

	local title = (args.nimi or mw.title.getCurrentTitle().prefixedText)
	local bgcolor = frame:expandTemplate{title = 'Musiikkialbumi/väri', args = {args.tyyppi}}
	local header = '<tr><th style="text-align:center; color:black; background:' .. bgcolor .. ';" colspan="3">[[Single]]t albumilta <i>' .. title .. '</i></th></tr>'

	-- concatenate at end
	local wiki = {}	
	local function insert( value )
		wiki[#wiki+1] = value
	end	
	local nums = getArgNums(args, '[Ss]ingle ')
	for _, num in ipairs(nums) do
		local name = (args['Single ' .. num] or args['single ' .. num])
		insert('<tr style="vertical-align:top;"><td style="text-align:left; padding-left:1em;" colspan="3">')
		insert('' .. tostring(num) ..'. ')
		insert('<span class="item"><span class="fn" style="font-size:95%">”')
		insert(name)
		insert('”</span>')
		local date = args['Single ' .. num .. ' pvm'] or args['single ' .. num .. ' pvm']
		if date then
			insert('<br /><span style="padding-left:1em;">Julkaistu: ')
			insert(date)
			insert('</span>')
		end
		insert('</span></td></tr>')
	end
	-- header and rows into string
	return header .. table.concat( wiki )
end

return p