Nieuwe pagina aangemaakt met '-- @param string jsonstr -- @todo: use new lua function that comes with WSSlots local p = {} function p.main ( frame ) local jsonstr = frame.args['jsonstr'] loc...' |
Also store a sorting value for SMW |
||
| (6 tussenliggende versies door dezelfde gebruiker niet weergegeven) | |||
| Regel 1: | Regel 1: | ||
-- @param string jsonstr | -- @param string jsonstr | ||
-- @todo: use new | -- @todo: use new Lua function that comes with WSSlots (available since Feb) | ||
local p = {} | local p = {} | ||
| Regel 10: | Regel 10: | ||
end | end | ||
function p.subobject( frame ) | 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 | end | ||
return p | |||
Huidige versie van 9 aug 2023 13:57
Module:Read award recognition
-- @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
