|
Labels: Vervangen Handmatige ongedaanmaking |
| (30 tussenliggende versies door 3 gebruikers niet weergegeven) |
| Regel 1: |
Regel 1: |
| local p = {} | | 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
| |
|
| |
| --[[
| |
| Local helper function for p.store
| |
| Stores each instance in a subobject
| |
| ]]--
| |
| local function store_award_as_subobject( frame, args, award, awardEvent )
| |
| -- local item = args?
| |
|
| |
| if mw.smw then
| |
| local subobject = {
| |
| ["Class"] = "Award recognition",
| |
| ["Belongs to award"] = award,
| |
| ["Belongs to award event"] = awardEvent,
| |
| ["Has position"] = args["Rank"] or false,
| |
| ["Has recognition type"] = args["Type"] or false,
| |
| ["Has category"] = args["Categorie"] or false,
| |
| ["Has recipient"] = mw.text.split( args["Title"], ',', plain ) or false,
| |
| ["Has description"] = args["Description"] or false
| |
| }
| |
|
| |
| -- 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
| |
| return
| |
| 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 jsonstr = frame.args["json"] or nil
| |
| if jsonstr == nil or jsonstr == "" then
| |
| --Fail silently
| |
| return
| |
| end
| |
|
| |
| local json = mw.text.jsonDecode( jsonstr )
| |
|
| |
| award = json["Award"] or false
| |
| awardEvent = json["AWard event"] or false
| |
|
| |
| -- #set
| |
| if mw.smw then
| |
| local setTable = {
| |
| ["Has name"] = json["Naam"] or false,
| |
| ["Has description"] = json["Description"] or false
| |
| }
| |
| end
| |
|
| |
| -- #subobjects
| |
| awardInstances = json["Awards"] or nil
| |
| if awardInstances ~= nil then
| |
| for i,v in ipairs( awardInstances ) do
| |
| store_award_as_subobject( frame, v, award, awardEvent )
| |
| end
| |
| end
| |
|
| |
| --ternary
| |
| --local sign = if x < 0 then 'negative' else 'non-negative' end
| |
| return json["Naam"]
| |
| 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 | | return p |