Moduuli:Tuotantoryhmä

Wikipediasta
Siirry navigaatioon Siirry hakuun

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Tuotantoryhmä/ohje

-- This module implements {{näyttelijä-rooli}} and {{tuotantoryhmä}}.

local p = {}


local function formatItem( data )
	if data == nil then
		return ''
	end
    if not type( data ) == 'string' then
        return ''
    end
    return mw.ustring.format( ' %s ', data )
end

local function buildList( args )
    -- Get the list items.
    local listItems = args
    if #listItems == 0 then
        return ''
    end

	local rootnode = mw.html.create()

	-- TODO:? if args['piilotettu'] tagclass('collapsible collapsed;') :cssText('border: #aaa 1px solid; padding: 3px;')
	-- TODO:? if args['leveys'] :css('max-width', args['leveys'])
	
	local listataulu = rootnode:tag('table')
	listataulu
		:attr('cellspacing', 0)
		:attr('cellpadding', 0)
		:cssText('background-color: transparent; color: black;')

	-- otsikko koko luettelolle jos annettu
	if (args['otsakekuvaus']) then
		local otsake = listataulu:tag('tr')
		otsake
			:tag('th')
				:attr('colspan', 10)
				:cssText('text-align: center; background-color: #fff; width: 100%;')
				:wikitext(args['otsakekuvaus'])		
	end
		
	-- jos otsikot == kyllä -> sarakkeiden otsikot
	-- otsikkoteksti (näyttelijä/rooli vs. henkilö/tehtävä)
	if (args['otsikot'] == 'kyllä') then
		local a = 'Näyttelijä'
		local b = 'Rooli'
		if (args['henkilö']) then
			a = args['henkilö']
		end
		if (args['tehtävä']) then
			b = args['tehtävä']
		end
		local otsikkorivi = listataulu:tag('tr')
		otsikkorivi
			:wikitext( '<th><span style="font-weight:bold;">' .. a .. '</span></th><th>&nbsp;</th><th><span style="font-weight:bold;">'.. b .. '</span></th>' )
	end

	local minimileveys = '10em'	
	if (args['minimileveys']) then
		minimileveys = args['minimileveys']
	end

	local k = 1
	local riviNro = 1
	while (k < #listItems) do
		local backgroundcolor
		if (riviNro % 2) == 0 then
			backgroundcolor = '#fff'
		else
			backgroundcolor = '#f2f2fc'
		end
		local colorstyle = 'color: black; background-color: ' .. backgroundcolor
		
		local rivi = listataulu:tag('tr')
		local soluA = rivi:tag('td')
		soluA
			:cssText('min-width: ' .. minimileveys .. '; ' .. colorstyle)
			:wikitext( formatItem( listItems[k] ) )
		
		-- kolme pistettä omaan sarakkeeseen (selkeä erottimena)
		local soluPisteet = rivi:tag('td')
		soluPisteet
			:cssText(colorstyle)
			:wikitext( '&hellip;' )
			
		local soluB = rivi:tag('td')
		soluB
			:cssText('min-width: ' .. minimileveys .. '; ' .. colorstyle)
			:wikitext( formatItem( listItems[k+1] ) )
		
		k = k+2
		riviNro = riviNro +1
	end

	return tostring(rootnode)
end

function p.main( frame )
    local origArgs
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
        for k, v in pairs( frame.args ) do
            origArgs = frame.args
            break
        end
    else
        origArgs = frame
    end
    
    local args = {}
    for k, v in pairs( origArgs ) do
        if type( k ) == 'number' or v ~= '' then
            args[ k ] = v
        end
    end
    return buildList( args )
end

return p