Module:Portable infobox

--[=[ Simple module to demostrate how to create a portable infobox + lua (hybrid) Ported from Portability Wiki for HPW by mfaizsyahmi, 2017 --]=]

local portable = {} local getArgs = require("Dev:Arguments").getArgs local testStructure = mw.loadData("Module:Portable infobox/data").testStructure

function portable.main(frame) local args = getArgs(frame) if args.test then return createPortable(testStructure) end end

function createPortable(dataDB) local portableOutput = {} for dataNode,content in pairs(dataDB) do       mw.log(dataNode) if dataNode == "title" then table.insert(portableOutput, createTitle(dataDB[dataNode].default)) end if dataNode =="structure" then for _, attribute in ipairs(dataDB.structure) do               if attribute.type == "data" then table.insert(portableOutput, createDataItem(attribute.source, attribute.label, attribute.default, attribute.dataFormat)) end if attribute.type == "image" then table.insert(portableOutput, createImageItem(attribute.source, attribute.default, attribute.caption, attribute.alt)) end end end end

local portableInfobox = preprocess("") return portableInfobox end

function createTitle(defaultText) local data =         ..(defaultText or "") .. return data end

function createImageItem(source, default, caption, alt) local data =         .. (caption or "") .. ..(default or "") ..         .. (alt or "") .. return data end

function createDataItem(source, label, default, dataFormat) local data = return data end

function preprocess(text) if mw.getCurrentFrame then return mw.getCurrentFrame:preprocess(text) end return text end return portable