Module:Fermentation
La documentation pour ce module peut être créée à Module:Fermentation/doc
local p = {}
local OUI = 'oui'
local LF = '\n'
------------------------------------------------
----- Référentiel des interactions -----
------------------------------------------------
local data = {
["fermentable"] = {note = function(args) return LF .. args["fermentable"] .. LF end},
["fermenté"] = {note = function(args) return LF .. args["fermenté"] .. LF end},
["mature"] = {note = function(args) return LF .. args["mature"] .. LF end}
}
------------------------------------------------
function buildRow(args, def)
local description = def.description
if type(def.description) == 'function' then
description = description(args)
end
description = mw.html.create( 'p' )
:wikitext( description )
:done()
local note = def.note
if note then
if type(note) == 'function' then
note = note(args)
end
end
return mw.html.create( 'li' )
:addClass( 'avt-interactions-row' )
:node(image)
:tag( 'div' )
:addClass( 'avt-interactions-text' )
:node(description)
:node(note)
:done()
end
function p._build(args)
local res = mw.html.create( 'ul' )
:addClass( 'avt-interactions' )
-- on trie les arguments par ordre alphabétique
local keys = {}
for k, v in pairs(args) do
table.insert(keys, k)
end
table.sort(keys)
local isEmpty = true
for i, key in ipairs(keys) do
argValue = args[key]
local def = data[key:lower()]
if def and (not def.checkIfYes or argValue:lower() == OUI) and argValue ~= '-' then
isEmpty = false
res:node(buildRow(args, def))
end
end
res:allDone()
return res
end
function p.build(frame)
local args = {}
local argsParent = frame:getParent().args
for cle, val in pairs(argsParent) do
if val then
val = mw.text.trim(val)
if val ~= '' then
args[cle] = mw.text.trim(val)
end
end
end
return p._build(args)
end
return p