|
Labels: Vervangen Handmatige ongedaanmaking |
| (7 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 below
| |
| Stores each instance in a subobject
| |
| ]]--
| |
| local function store_award_as_subobject( frame, args, awardCategory, awardEvent, award )
| |
| if mw.smw then
| |
| 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( args["Title"], ',', 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 category
| |
| |store
| |
| |json={{#slot:ws-data|{{FULLPAGENAME}} }}
| |
| }}
| |
|
| |
| ]]--
| |
| function p.store( frame )
| |
| local jsonstr = frame.args["json"] or nil
| |
| local page = frame.args["page"] or nil
| |
| local id = frame.args["id"] or ""
| |
|
| |
| if jsonstr == nil or jsonstr == "" or page == nil or page == "" then
| |
| --Fail silently. Do nothing
| |
| return
| |
| end
| |
| local json = mw.text.jsonDecode( jsonstr )
| |
|
| |
| -- get awardEvent on the basis of the page nane
| |
| if page ~= nil then
| |
| local pageParts = mw.text.split( page, "/" )
| |
| table.remove( pageParts );
| |
| awardEvent = table.concat( pageParts, "/" )
| |
| end
| |
|
| |
| local award = json["Award"] or ""
| |
| local awardEvent = json["Award event"] or awardEvent
| |
|
| |
| local test = json["Name"]
| |
|
| |
| -- #set:
| |
| if mw.smw then
| |
| local setTable = {
| |
| -- Dutch-language label
| |
| ["Klasse"] = "Prijscategorie",
| |
| ["Has ID"] = id,
| |
| ["Title"] = json["Name"] or "",
| |
| ["Has name"] = json["Name"] or "",
| |
| ["Has description"] = json["Description"] or "",
| |
| ["Belongs to award"] = award or "",
| |
| ["Belongs to award event"] = awardEvent or ""
| |
| }
| |
| local 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
| |
|
| |
| --[[
| |
| ]]--
| |
| 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 |