Nieuwe pagina aangemaakt met 'local p = {} --[[ Ignore - generic 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 --Local helper function for p.store below Stores each instance in a subobject -- local function store_award_as_subobject( frame, args, awardCategory, awardEvent, award ) if mw.smw…' |
Geen bewerkingssamenvatting |
||
| Regel 41: | Regel 41: | ||
Consider using Lua version of parser function instead | Consider using Lua version of parser function instead | ||
{{#invoke:Award category | {{#invoke:Award event category|store | ||
|store | |json={{#slot:ws-data|{{FULLPAGENAME}} }} // old style | ||
|json={{#slot:ws-data|{{FULLPAGENAME}} }} | |page={{FULLPAGENAME}} | ||
|slot=ws-data | |||
|id= | |||
}} | }} | ||
| Regel 50: | Regel 52: | ||
local jsonstr = frame.args["json"] or nil | local jsonstr = frame.args["json"] or nil | ||
local page = frame.args["page"] or nil | local page = frame.args["page"] or nil | ||
local id = frame.args["id"] or "" | local id = frame.args["id"] or "" -- are we still using this? | ||
if jsonstr == nil or jsonstr == "" or page == nil or page == "" then | if jsonstr == nil or jsonstr == "" or page == nil or page == "" then | ||
| Regel 58: | Regel 60: | ||
local json = mw.text.jsonDecode( jsonstr ) | local json = mw.text.jsonDecode( jsonstr ) | ||
local awardEvent = json["Award event"] or awardEvent | local awardEvent = json["Award event"] or awardEvent | ||
local test = json["Name"] | local test = json["Name"] | ||
-- @todo derive name from category + event? | |||
local name = json["Name"] or "" | |||
-- #set: | -- #set: | ||
local setResult = nil | |||
if mw.smw then | if mw.smw then | ||
local setTable = { | local setTable = { | ||
-- Dutch-language label | -- Dutch-language label | ||
["Klasse"] = "Prijscategorie", | ["Klasse"] = "Prijscategorie op evenement", | ||
["Has ID"] = id, | ["Has ID"] = id, | ||
[" | --["Belongs to award"] = json["Award"] or "" | ||
[" | ["Belongs to award event"] = awardEvent, | ||
[" | ["Belongs to award category"] = json["AwardCategory"], | ||
["Has | --["Title"] = json["Name"] or "", | ||
[" | --["Has name"] = json["Name"] or "", | ||
[" | --["Has description"] = json["Description"] or "", | ||
--["Has category"] = json["Category"] or "" | |||
} | } | ||
setResult = mw.smw.set( setTable ) | |||
end | end | ||
| Regel 130: | Regel 129: | ||
end | end | ||
return res | return res | ||
end | |||
--[[ @todo maybe - naming has changed so this won't work ]]-- | |||
p.getAwardEventFromPageName = function( page ) | |||
local awardEvent = nil | |||
-- get awardEvent on the basis of the page name | |||
if page ~= nil then | |||
local pageParts = mw.text.split( page, "/" ) | |||
-- ??? remove last part ?? | |||
table.remove( pageParts ); | |||
--- ?? | |||
awardEvent = table.concat( pageParts, "/" ) | |||
end | |||
return awardEvent | |||
end | end | ||
return p | return p | ||
Versie van 5 sep 2025 20:32
Module:Award event category
local p = {}
--[[
Ignore - generic 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
--[[
Local helper function for p.store below
Stores each instance in a subobject
]]--
local function store_award_as_subobject( frame, args, awardCategory, awardEvent, award )
if mw.smw then
local recipient = args["Title"] or args["Book"] or args["Person"] or ""
local subobject = {
["Class"] = "Award recognition",
["Belongs to award"] = award or "",
["Belongs to award event"] = awardEvent or "",
["Belongs to award category"] = awardCategory or "",
["Has position"] = args["Rank"] or "",
["Has recognition type"] = args["Type"] or "",
["Has category"] = args["Categorie"] or "",
["Has recipient"] = mw.text.split( recipient, ',', true ) or "",
["Has description"] = args["Description"] or ""
}
local subobjectStore = mw.smw.subobject( subobject )
end
return
end
--[[
Store in SMW
Consider using Lua version of parser function instead
{{#invoke:Award event category|store
|json={{#slot:ws-data|{{FULLPAGENAME}} }} // old style
|page={{FULLPAGENAME}}
|slot=ws-data
|id=
}}
]]--
function p.store( frame )
local jsonstr = frame.args["json"] or nil
local page = frame.args["page"] or nil
local id = frame.args["id"] or "" -- are we still using this?
if jsonstr == nil or jsonstr == "" or page == nil or page == "" then
--Fail silently. Do nothing
return
end
local json = mw.text.jsonDecode( jsonstr )
local awardEvent = json["Award event"] or awardEvent
local test = json["Name"]
-- @todo derive name from category + event?
local name = json["Name"] or ""
-- #set:
local setResult = nil
if mw.smw then
local setTable = {
-- Dutch-language label
["Klasse"] = "Prijscategorie op evenement",
["Has ID"] = id,
--["Belongs to award"] = json["Award"] or ""
["Belongs to award event"] = awardEvent,
["Belongs to award category"] = json["AwardCategory"],
--["Title"] = json["Name"] or "",
--["Has name"] = json["Name"] or "",
--["Has description"] = json["Description"] or "",
--["Has category"] = json["Category"] or ""
}
setResult = mw.smw.set( setTable )
end
-- #subobjects
local awardInstances = json["Awards"] or nil
if awardInstances ~= nil then
local awardCategory = page
for i, v in ipairs( awardInstances ) do
local subobjectStore = store_award_as_subobject( frame, v, awardCategory, awardEvent, award )
end
end
--ternary
--local sign = if x < 0 then 'negative' else 'non-negative' end
return "test"
end
--[[
use a template to format a (Lua) table
]]--
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_award_recognitions( frame )
local jsonstr = frame.args["json"] or nil
local page = frame.args["page"] or page
local template = frame.args["template"] or nil
res = ""
if jsonstr ~= nil then
local json = mw.text.jsonDecode( jsonstr )
local awards = json["Awards"] or nil
if awards == nil then return "" end
for i,v in ipairs(awards) do
res = res .. send_to_template( frame, template, v )
end
--
--etc
end
return res
end
--[[ @todo maybe - naming has changed so this won't work ]]--
p.getAwardEventFromPageName = function( page )
local awardEvent = nil
-- get awardEvent on the basis of the page name
if page ~= nil then
local pageParts = mw.text.split( page, "/" )
-- ??? remove last part ??
table.remove( pageParts );
--- ??
awardEvent = table.concat( pageParts, "/" )
end
return awardEvent
end
return p
