No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function Sponsors.make(results, frame) | function Sponsors.make(results, frame) | ||
if type(results) ~= 'table' then results = _.encode(results) end | |||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
Line 17: | Line 18: | ||
return container | return container | ||
end | |||
function _.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 | end | ||
return Sponsors | return Sponsors |
Revision as of 07:26, 15 May 2023
Documentation for this module may be created at Module:Infobox/Widget/Sponsors/doc
local Sponsors = {}
function Sponsors.make(results, frame)
if type(results) ~= 'table' then results = _.encode(results) end
local container = mw.html.create('div')
for r = 1, #results do
local result = results[r]
local sponsor = mw.html.create('div')
:wikitext('[[' .. result.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 _.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