Module:GetData: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) |
||
| Line 19: | Line 19: | ||
if dataStored == true then | if dataStored == true then | ||
return ' | return '' | ||
else | else | ||
return 'An error occurred during the storage process. Message reads ' .. dataStored.error | return 'An error occurred during the storage process. Message reads ' .. dataStored.error | ||
Revision as of 00:22, 23 September 2023
Documentation for this module may be created at Module:GetData/doc
local p = {}
function p.set(frame)
local pData = mw.loadData('Module:GetData/'..frame.args['data'])
local parentArgs = frame:getParent().args
local props = parentArgs.prop
local dataStore = {}
for propValue in string.gmatch(props, "([^;]+)") do
table.insert(dataStore, propValue .. '=' .. pData[propValue])
if parentArgs.sep ~= "" and parentArgs.sep ~= nil then
local propValueSep = parentArgs.sep
table.insert(dataStore, '+sep=' .. propValueSep)
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
end
function p.main(frame)
local pData = mw.loadData('Module:GetData/'..frame.args['data'])
local parentArgs = frame:getParent().args
local props = parentArgs.prop
local propTable = {}
for propValue in string.gmatch(props, "([^;]+)") do
table.insert(propTable, propValue)
end
local finalString = ""
if parentArgs.intro ~= "" and parentArgs.intro ~= nil then
for k,v in ipairs(propTable) do
if pData[v] ~= "" then
finalString = parentArgs.intro
end
end
end
for i,prop in pairs(propTable) do
if pData[prop] ~= "" and pData[prop] ~= nil then
local pdString = pData[prop]
local pdTable = {}
if parentArgs.sep ~= "" and parentArgs.sep ~= nil then
local sep = parentArgs.sep
for value in string.gmatch(pdString, "([^" .. sep .. "]+)") do
table.insert(pdTable, value)
end
else
table.insert(pdTable, pdString)
end
if parentArgs.map ~= "" and parentArgs.map ~= nil then
local map = parentArgs.map
pdString = ""
for k,v in pairs(pdTable) do
mapdVal = string.gsub(map, "@@@", v)
pdString = pdString .. mapdVal
end
end
if parentArgs.printsep ~= "" and parentArgs.printsep ~= nil then
finalString = finalString .. parentArgs.printsep .. frame:preprocess( pdString )
if mw.ustring.sub(finalString, 1, 1) == parentArgs.printsep then
finalString = mw.ustring.sub(finalString, 2)
end
else
finalString = finalString .. frame:preprocess( pdString )
end
end
end
if parentArgs.outro ~= "" and parentArgs.outro ~= nil then
for k,v in ipairs(propTable) do
if pData[v] ~= "" then
finalString = finalString .. parentArgs.outro
end
end
end
if parentArgs.silent ~= "yes" then
if finalString ~= "" and finalString ~= nil then
return finalString
else
if parentArgs.default ~= "" and parentArgs.default ~= nil then
return parentArgs.default
end
end
end
end
return p