-- @param string jsonstr
-- @todo: use new Lua function that comes with WSSlots (available since Feb)
local p = {}
function p.main ( frame )
local jsonstr = frame.args['jsonstr']
local output = jsonstr
return output
end
local function send_to_template( frame, templateName, argsTable )
if templateName ~= nil and argsTable ~= nil then
return frame:expandTemplate{ title = templateName, args = argsTable }
else
return ""
end
end
function p.show_in_list( frame )
local jsonstr = frame.args['jsonstr'] or nil
if jsonstr == nil or jsonstr == "" then
return error("No JSON string found")
end
local resultTemplateName = frame.args['template'] or nil
local jsondata = mw.text.jsonDecode( jsonstr )
local awardsTitle = jsondata["Title"]
local firstWinner = jsondata["Awards"][1]["winner"]
local winners = jsondata["Awards"]
local output = ""
for i, v in ipairs( winners ) do
local item = v -- array { "name"="Stephen", "rank"="" }
local name = v["winner"] or ""
local nameArr = mw.text.split( name, ',', plain )
local rank = v["rank"] or ""
--function here - set for SMW or show on page
--local win = "<div>" .. rank .. ". " .. name .. "</div>"
--output = output .. win
--subobject
if mw.smw then
local subobjectTable = {}
subobjectTable['Has sort number'] = i
subobjectTable['Has name'] = nameArr
subobjectTable['Has rank'] = rank
local subobjectStore = mw.smw.subobject( subobjectTable )
end
--presentation through template
local templateArgsTable = { Name = name, Rank = rank }
output = output .. send_to_template( frame, resultTemplateName, templateArgsTable )
end
--local datatype = awardsTitle .. "<br>" .. firstWinner
return output
end
return p