Jump to content

Module:Team roster navbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix
simplify
Line 17: Line 17:
local function extractstyle(v)
local function extractstyle(v)
local r = ''
local r = ''
if v and v ~= '' then
local slist = mw.text.split(v or '', ';')
for k = 1,#slist do
v = v .. ';'
local s = slist[k]
v = mw.ustring.gsub(v, 'border%s*:[^;]*', '')
if s:match('^[%s]*background') or s:match('^[%s]*color') then
r = r .. s .. ';'
end
end
end
return v
return r
end
end
function me.generateRosterNavbox(frame)
function me.generateRosterNavbox(frame)
Line 28: Line 31:
-- Massage the styles for coloring the links
-- Massage the styles for coloring the links
local titlestyle = parentArgs['titlestyle'] or ''
local basestyle = extractstyle(parentArgs['basestyle'] or '')
local abovestyle = parentArgs['abovestyle'] or ''
local titlestyle = extractstyle(parentArgs['titlestyle'] or '')
local groupstyle = parentArgs['groupstyle'] or ''
local abovestyle = extractstyle(parentArgs['abovestyle'] or '')
local belowstyle = parentArgs['belowstyle'] or ''
local groupstyle = extractstyle(parentArgs['groupstyle'] or '')
local basestyle = parentArgs['basestyle'] or ''
local belowstyle = extractstyle(parentArgs['belowstyle'] or '')
if basestyle ~= '' then
if basestyle ~= '' then
Line 40: Line 43:
belowstyle = basestyle .. ';' .. belowstyle
belowstyle = basestyle .. ';' .. belowstyle
end
end
titlestyle = extractstyle(titlestyle)
abovestyle = extractstyle(abovestyle)
groupstyle = extractstyle(groupstyle)
belowstyle = extractstyle(belowstyle)

-- Color links before passing them to the Navbox helper function
-- Color links before passing them to the Navbox helper function
for argName, value in pairs(parentArgs) do
for argName, value in pairs(parentArgs) do

Revision as of 13:18, 3 June 2017

-- This module implements {{team roster navbox}}
local me = { }

local Navbox = require('Module:Navbox')

local function colorlinks(v, s)
	if v and v ~= '' and s and s ~= '' then
		if not mw.ustring.match(v, '<span style') then
			v = mw.ustring.gsub(v, '%[%[([^%[%]|]*)%]%]', 
				'[[%1|<span style="' .. s .. '>%1</span>]]')
			v = mw.ustring.gsub(v, '%[%[([^%[%]|]*)|([^%[%]|]*)%]%]', 
				'[[%1|<span style="' .. s .. '>%2</span>]]')
		end
	end
	return v
end
local function extractstyle(v)
	local r = ''
	local slist = mw.text.split(v or '', ';')
	for k = 1,#slist do
		local s = slist[k]
		if s:match('^[%s]*background') or s:match('^[%s]*color') then
			r = r .. s .. ';'
		end
	end
	return r
end	
function me.generateRosterNavbox(frame)
    local args = { }
    local parentArgs = frame:getParent().args
    
    -- Massage the styles for coloring the links
    local basestyle  = extractstyle(parentArgs['basestyle'] or '')
    local titlestyle = extractstyle(parentArgs['titlestyle'] or '')
    local abovestyle = extractstyle(parentArgs['abovestyle'] or '')
    local groupstyle = extractstyle(parentArgs['groupstyle'] or '')
    local belowstyle = extractstyle(parentArgs['belowstyle'] or '')
    
    if basestyle ~= '' then
    	titlestyle = basestyle .. ';' .. titlestyle
    	abovestyle = basestyle .. ';' .. abovestyle
    	groupstyle = basestyle .. ';' .. groupstyle
    	belowstyle = basestyle .. ';' .. belowstyle
    end
    
    -- Color links before passing them to the Navbox helper function
    for argName, value in pairs(parentArgs) do
        if value ~= '' then
            if type(argName) == 'string' then
                if argName == 'title' then
                    value = colorlinks(value, titlestyle)
                elseif argName == 'above' then
                    value = colorlinks(value, abovestyle)
                elseif mw.ustring.find(argName, '^group[0-9]') then
                    value = colorlinks(value, groupstyle)
                elseif argName == 'below' then
                    value = colorlinks(value, belowstyle)
                end
                args[argName] = value
            end
        end
    end
    args['nowrapitems'] = 'yes'

    -- Note Navbox.navbox() has a kludge to order the parent frame's args
    -- into a specific order. For now, this is omitted from this module.

    return Navbox._navbox(args)

end  -- function me.generateRosterNavbox

return me