Module:RecipeRow
Appearance
Documentation for this module may be created at Module:RecipeRow/doc
local util_args = require("Module:ArgsUtil")
local util_cache = require("Module:CacheUtil")
local util_vars = require("Module:VarsUtil")
local cache = require('mw.ext.LuaCache')
local p = {}
local h = {}
function p.Main(frame)
local args = util_args.mergeKeepEmpty()
-- prepare array with the incredients
local ingredientsList = {}
for n = 1, 4 do
local i = args["i" .. n]
local q = args["iq" .. n]
if i and q then
ingredientsList[#ingredientsList + 1] = q .. ' ' .. h.getFromVariablesOrCache(frame, i)
end
end
-- prepare array with the outcomes
local outcomesList = {}
for n = 1, 4 do
local i = args["o" .. n]
local q = args["oq" .. n]
if i and q then
outcomesList[#outcomesList + 1] = q .. ' ' .. frame:callParserFunction('#invoke:ItemLink', 'Main', i)
end
end
local ct = args.ct or ''
local xp = args.xp or 0
local temp = '|-\n' ..
'|' .. table.concat(ingredientsList, '<br>') .. '\n' ..
'|' .. table.concat(outcomesList, '<br>') .. '\n' ..
'|style="text-align:center"|' .. ct .. '||style="text-align:center"|' .. xp
return temp
end
function h.getFromVariablesOrCache(frame, key)
return util_vars.getObject(key) or h.getFromCacheOrParseFunction(frame, key)
end
function h.getFromCacheOrParseFunction(frame, key)
local result = cache.get(key) or h.getFromParseFunctionAndUpdateCache(frame, key)
util_vars.setObject(key, result)
return result
end
function h.getFromParseFunctionAndUpdateCache(frame, key)
local result = frame:callParserFunction('#invoke:ItemLink', 'Main', key)
cache.set(key, result)
return result
end
-- function h.getItemLink(frame, name)
-- local cached = itemLinkCache[name]
-- if cached then
-- return cached .. "C"
-- end
-- local link = frame:callParserFunction('#invoke:ItemLink', 'Main', name)
-- itemLinkCache[name] = link
-- return link
-- end
return p