Module:Role

local lang = mw.getLanguage('en') local util_args = require('Module:ArgsUtil') local LOOKUP = mw.loadData('Module:Rolenames') local util_table = require('Module:TableUtil')

local h = {}

function h.getInfo(str, settings) if str == '' then str = nil end if settings.sub then settings.div = true if str then settings.sortnumber = 20 settings.modifysub = true else settings.sortnumber = 10 str = 'substitute' end else if str then settings.sortnumber = 10 else str = '' end end local default = { adjective = str, short = str, role = str, rolelc = lang:lc(str or ''), sentence = (str or '') .. ' for', article = 'a', sortnumber = 70 }	settings.vars = util_args.lookupVars(str, LOOKUP, settings.allowdefault) or default return end

function h.sortnumber(tbl, n, doanything) if not doanything then return end tbl:tag('span') :cssText('display:none;') :wikitext(n) return end

function h.addImage(tbl, settings) local function addImage(tbl, role, size) tbl:wikitext((''):format(role, size or '15px')) end tbl:attr('title',settings.vars.role) :addClass('role-icon') if settings.sub then local img = tbl:tag('div') :addClass('role-icon-sub-image') addImage(img, settings.vars.role, settings.size) tbl:tag('div'):addClass('role-icon-sub-s'):wikitext('S') else addImage(tbl, settings.vars.role, settings.size) end return tbl end

local p = {}

function p.main(frame) -- this should NEVER be called from Lua, only invoked from MW	local args = util_args.merge(true) if not args[1] and not args.sub then return '' end local style = args[2] or 'rolename' return p[style](args[1], args) end

function p.onlyimage(str, settings) if not settings then settings = {} end h.getInfo(str, settings) local tbl = mw.html.create('div') if settings.sorted then tbl:wikitext(h.sortnumber(settings.vars.sortnumber + settings.sortnumber)) end return tostring(h.addImage(tbl, settings)) end

function p.sentencemultiple(str, settings) if not settings then settings = {} end h.getInfo(str, settings) local tbl = { settings.vars.article, settings.modifysub and 'substitute', settings.vars.sentence }	return util_table.concat(tbl, ' ') end

function p.rolelc(str, settings) if not settings then settings = {} end h.getInfo(str, settings) return settings.vars.rolelc end

function p.sentence(str, settings) if not settings then settings = {} end h.getInfo(str, settings) local tbl = { settings.modifysub and 'substitute', settings.vars.sentence }	return util_table.concat(tbl, ' ') end

function p.roleonly(str, settings) -- Ignores whether it's a sub or not if not settings then settings = {} end h.getInfo(str, settings) local tbl = mw.html.create h.sortnumber(tbl, settings.vars.sortnumber, settings.sorted) tbl:wikitext(settings.vars.role) return tostring(tbl) end

function p.shortname(str, settings) if not settings then settings = {} end h.getInfo(str, settings) local tbl = mw.html.create h.sortnumber(tbl, settings.vars.sortnumber, settings.sorted) tbl:wikitext(settings.vars.short) return tostring(tbl) end

function p.rolename(str, settings) if not settings then settings = {} end h.getInfo(str, settings) local tbl = mw.html.create h.sortnumber(tbl, settings.vars.sortnumber, settings.sorted) if settings.modifysub then tbl:wikitext(('Sub/%s'):format(settings.vars.short)) else tbl:wikitext(settings.vars.role) end return tostring(tbl) end

function p.default(str, settings) -- deprecated, do not use pls ty	return p.rolename(str, settings) end

return p