FANDOM


local Infobox = {}
----------------------------
-- Libraries of functions --
----------------------------
-- stands for High Frequency
local HF = require('Module:ComicsHF')
-- Parses invocation parameters, trims whitespace, and removes blanks
local getArgs = require('Dev:Arguments').getArgs
-- Common and centralized functions
local ComicsInfobox = require('Module:ComicsInfobox')
 
-----------------------
-- Libraries of data --
-----------------------
-- Various data tables which can be refactored for paradigm
-- Citizenship and Race can be sorted into: 
-- * dataCitizenship_dc
-- * dataCitizenship_marvel
local ctznTable       = mw.loadData('Module:ComicsInfobox/dataCitizenship_marvel')
 
-- Since this should only be evaluated once per pageview, it's now global
_G.vars = { Pagename = mw.title.getCurrentTitle().text }
 
local function transition(funcName)
  -- This module's initial functions were made for InfoboxBuilder.
  -- As a result, most of them can't be invoked for Portable Infoboxes.
  -- To allow the existing code without rewriting it, this wrapper allows invocation.
	return function (frame)
		local args = getArgs(frame, { trim = true, removeBlanks = true })
		return Infobox[funcName](args, vars)
	end
end
 
Infobox.Citizenship = transition('_Citizenship')
 
---------------------
-- Local functions --
---------------------
 
local CitizenshipCheck = function( values, table )
  local output = ""
  local valueUpper = ""
  local valueLower = ""
  local pagename = vars.Pagename
 
    for i, value in ipairs( values ) do
      if type( value ) ~= nil then
        valueUpper = HF.firstToUpper( HF.trim( value ) )
        valueLower = string.lower( HF.trim( value ) )
 
        if type( table.valid[valueUpper] ) ~= nil and table.valid[valueUpper] == true then
          output = output .. HF.CategoryLink( valueUpper, pagename, valueUpper ) .. ", "
        elseif type( table.substitutes[valueLower] ) == "string" then
          output = output .. HF.CategoryLink( table.substitutes[valueLower], pagename, valueUpper ) .. ", "
        else
          output = output .. value .. ", "
        end
      else
        output = output .. value
      end
    end
 
  return output
end
 
----------------------
-- Public functions --
----------------------
 
function Infobox._Citizenship( field, vars )
    local output = {}
    if not HF.isempty( field.Value ) then
        table.insert( output, CitizenshipCheck( HF.explode( ',', field.Value), ctznTable ) )
    end
 
    if not HF.isempty( field.Value2 ) then
        table.insert( output, CitizenshipCheck( HF.explode( ',', field.Value2), ctznTable ) )
    end
 
  return table.concat(output, ', ')
end
 
return Infobox

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.