Module:Infobox/Widget/Sponsors: Difference between revisions

From TwogPedia
(Created page with "local Sponsors = {} function Sponsors.make(sponsorArr, variant) local container = mw.html.create('div') -- :addClass('ib-sponsors') local sponsorList = mw.text.split(sponsorArr, ',') for i, v in ipairs(sponsorList) do v = mw.text.trim(v) local pageExists = mw.getCurrentFrame():callParserFunction('#ifexist', v, 'yes', 'no' ) local div = mw.html.create('div') if ( pageExists == 'yes' ) then div:wikitext('' .. v .. '') else div:wik...")
 
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
local Sponsors = {}
local Sponsors = {}


function Sponsors.make(sponsorArr, variant)
function Sponsors.make(results, frame)
    if type(results) == 'string' then results = Sponsors.encode(results) end
local container = mw.html.create('div')
local container = mw.html.create('div')
-- :addClass('ib-sponsors')
 
local sponsorList = mw.text.split(sponsorArr, ',')
for r = 1, #results do
local result = results[r]
for i, v in ipairs(sponsorList) do
        local id = string.gsub(result.id, 'Companies/', '')
v = mw.text.trim(v)
        local sponsor = mw.html.create('div')
local pageExists = mw.getCurrentFrame():callParserFunction('#ifexist', v, 'yes', 'no' )
        :wikitext('[[Companies/' .. id .. '|' .. id .. ']]')
local div = mw.html.create('div')
        if result.startRef or result.startRefName then
if ( pageExists == 'yes' ) then
        local startRefName = result.startRefName or ''
div:wikitext('[[' .. v .. '|' .. v .. ']]')
        local startRef = result.startRef or ''
else
        sponsor:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..startRef.. '</ref>'))
div:wikitext(v)
        end
end
        container:node(sponsor)
container:node(div)
    end
end


return container
return container
end
end


function Sponsors.encode(jsonString)
    local decodedTables = {}
    for objectString in jsonString:gmatch('{.-}') do
        local decodedTable = {}
   
        for key, value in objectString:gmatch('"(%w+)":"([^"]+)"') do
            decodedTable[key] = value
        end
   
        table.insert(decodedTables, decodedTable)
    end
    return decodedTables
end


return Sponsors
return Sponsors

Latest revision as of 21:28, 14 February 2024

Documentation for this module may be created at Module:Infobox/Widget/Sponsors/doc

local Sponsors = {}

function Sponsors.make(results, frame)
    if type(results) == 'string' then results = Sponsors.encode(results) end
	local container = mw.html.create('div')

	for r = 1, #results do
		local result = results[r]
        local id = string.gsub(result.id, 'Companies/', '')
        local sponsor = mw.html.create('div')
        	:wikitext('[[Companies/' .. id .. '|' .. id .. ']]')
        if result.startRef or result.startRefName then
        	local startRefName = result.startRefName or ''
        	local startRef = result.startRef or ''
        	sponsor:wikitext(frame:preprocess('<ref name='.. startRefName .. '>' ..startRef.. '</ref>'))
        end
        container:node(sponsor)
    end

	return container
end

function Sponsors.encode(jsonString)
    local decodedTables = {}

    for objectString in jsonString:gmatch('{.-}') do
        local decodedTable = {}
    
        for key, value in objectString:gmatch('"(%w+)":"([^"]+)"') do
            decodedTable[key] = value
        end
    
        table.insert(decodedTables, decodedTable)
    end

    return decodedTables
end

return Sponsors