Module:RemoteData: Difference between revisions
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) |
||
Line 5: | Line 5: | ||
local args = frame.args | local args = frame.args | ||
local pargs = frame:getParent().args | local pargs = frame:getParent().args | ||
local prop = pargs[1] | local prop = '' | ||
if args.prop then | |||
prop = args.prop | |||
else | |||
prop = pargs[1] | |||
end | |||
local source = args.source | local source = args.source | ||
Revision as of 15:09, 22 January 2025
Documentation for this module may be created at Module:RemoteData/doc
local p = {}
function p.get(frame)
local args = frame.args
local pargs = frame:getParent().args
local prop = ''
if args.prop then
prop = args.prop
else
prop = pargs[1]
end
local source = args.source
local remoteData = mw.smw.ask( '[[' .. mw.title.getCurrentTitle().subpageText .. ']]|?' .. prop .. '#|mainlabel=-|source=' .. source )
if remoteData then
for _, data in pairs( remoteData ) do
for property, value in pairs( data ) do
return frame:preprocess( value )
end
end
else
return 'No data! ¯\\_(ツ)_/¯'
end
end
function p.set(frame)
local pargs = frame:getParent().args
local props = pargs.props
local sep = pargs.sep
local source = pargs.source
local propString = ''
for property in string.gmatch(props, "([^;]+)") do
propString = propString .. '|?' .. property .. '#'
end
local valuesep = ''
if sep then
valuesep = '|valuesep=' .. sep
end
local remoteData = mw.smw.ask( '[[' .. mw.title.getCurrentTitle().subpageText .. ']]' .. propString .. valuesep .. '|mainlabel=-|source=' .. source )
if remoteData then
local dataStore = {}
for _, data in pairs( remoteData ) do
for property, value in pairs( data ) do
table.insert(dataStore, property .. '=' .. frame:preprocess( value ))
if sep then
table.insert(dataStore, '+sep=' .. sep)
end
end
end
local dataStored = mw.smw.set( dataStore )
if dataStored == true then
return ''
else
return 'An error occurred during the storage process. Message reads ' .. dataStored.error
end
else
return 'no remoteData'
end
end
return p