Geen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
| Regel 59: | Regel 59: | ||
if mw.smw then | if mw.smw then | ||
local subobject = {} | local subobject = {} | ||
subobject["Has rank number"] = args["Rank"] or | subobject["Has rank number"] = args["Rank"] or false | ||
subobject["Has type"] = args["Type"] or | subobject["Has type"] = args["Type"] or false | ||
subobject["Has category"] = args["Categorie"] or | subobject["Has category"] = args["Categorie"] or false | ||
local titles = args["Title"] or | local titles = args["Title"] or false | ||
-- more than one allowed?? | -- more than one allowed?? | ||
-- subobject["For title"] = | -- subobject["For title"] = | ||
subobject["description"] = args["Description"] or | subobject["description"] = args["Description"] or false | ||
-- etc | -- etc | ||
-- remove false | |||
local newSubobject = {}; | |||
for k,v in ipairs(subobject) do | |||
if v then | |||
newSubobject[k] = v | |||
end | |||
end | |||
local subobjectStore = mw.smw.subobject( newSubobject ) | |||
end | end | ||
end | end | ||
Versie van 29 dec 2024 15:50
Module:Award category
local p = {}
--[[
test test
{{#invoke:Award category |main |json={{#slot:ws-data|{{FULLPAGENAME}}}} }}
]]--
function p.main ( frame )
local json = frame.args["json"]
if json == nil or json == "" then
return error("No JSON string found")
end
return json
end
--[[
Store in SMW
Consider using Lua version of parser function instead
{{#invoke:Award category
|store
|json={{#slot:ws-data|{{FULLPAGENAME}} }}
}}
]]--
function p.store( frame )
local json = frame.args['json'] or nil
if json == nil or json == "" then
--Fail silently
return
end
--etc etc
-- #set
if mw.smw then
local setTable = {}
setTable["Has name"] = json["Naam"] or nil
setTable["Has description"] = json["Description"] or nil
end
-- #subobjects
local awardInstances = json["Awards"] or nil
if awardInstances ~= nil then
for i, v in ipairs( awardInstances ) do
local test = store_award_as_subobject( frame, v )
end
end
end
--[[
Local helper function for p.store
Stores each instance in a subobject
]]--
local function store_award_as_subobject( frame, args )
-- local item = args?
if mw.smw then
local subobject = {}
subobject["Has rank number"] = args["Rank"] or false
subobject["Has type"] = args["Type"] or false
subobject["Has category"] = args["Categorie"] or false
local titles = args["Title"] or false
-- more than one allowed??
-- subobject["For title"] =
subobject["description"] = args["Description"] or false
-- etc
-- remove false
local newSubobject = {};
for k,v in ipairs(subobject) do
if v then
newSubobject[k] = v
end
end
local subobjectStore = mw.smw.subobject( newSubobject )
end
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
return p
