« Module:Fermentation » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 3 : | Ligne 3 : | ||
local LF = '\n' | local LF = '\n' | ||
-------------------------------- | |||
----- Référentiel | ----- Référentiel ----- | ||
-------------------------------- | |||
local data = { | local data = { | ||
["fermentable"] = { | ["fermentable"] = { | ||
description = "Premier stade du brassage." | |||
}, | }, | ||
["fermenté"] = { | ["fermenté"] = { | ||
description = "Second stade du brassage." | |||
}, | }, | ||
["mature"] = { | ["mature"] = { | ||
description = "Troisième stade du brassage." | |||
} | } | ||
} | } | ||
-------------------------------- | |||
function buildRow( | function buildRow(argValue, def) | ||
local note = | local note = argValue or '' | ||
if note | if note ~= '' then note = LF .. note .. LF end | ||
return mw.html.create( 'li' ) | return mw.html.create( 'li' ) | ||
Ligne 39 : | Ligne 29 : | ||
:tag( 'div' ) | :tag( 'div' ) | ||
:addClass( 'avt-interactions-text' ) | :addClass( 'avt-interactions-text' ) | ||
:tag( 'p' ) | |||
:wikitext(def.description) | |||
:done() | |||
:wikitext( note ) | :wikitext( note ) | ||
:done() | |||
:tag( 'li' ) | |||
:wikitext( '[[Fichier:Icon_range_inverse.png|x50px|center]]' ) | |||
:done() | :done() | ||
end | end | ||
function p._build(args) | function p._build(args) | ||
local res = mw.html.create( 'ul' ) | local res = mw.html.create( 'ul' ) | ||
:addClass( 'avt-interactions' ) | :addClass( 'avt-interactions' ) | ||
local isEmpty = true | |||
for key, value in pairs(args) do | |||
for | |||
local def = data[key:lower()] | local def = data[key:lower()] | ||
if def and | if def and value ~= '-' and value ~= 'vide' then | ||
isEmpty = false | isEmpty = false | ||
res:node(buildRow( | res:node(buildRow(value, def)) | ||
end | end | ||
end | end | ||
-- cas particulier | -- cas particulier l'inventaire du pnj est vide | ||
if isEmpty then | if isEmpty then | ||
res:node(buildRow( | res:node(buildRow(nil, data.vide)) | ||
end | end | ||
Ligne 83 : | Ligne 70 : | ||
val = mw.text.trim(val) | val = mw.text.trim(val) | ||
if val ~= '' then | if val ~= '' then | ||
args[cle] = | args[cle] = val | ||
end | end | ||
end | end |
Version du 19 juillet 2021 à 17:24
La documentation pour ce module peut être créée à Module:Fermentation/doc
local p = {}
local LF = '\n'
--------------------------------
----- Référentiel -----
--------------------------------
local data = {
["fermentable"] = {
description = "Premier stade du brassage."
},
["fermenté"] = {
description = "Second stade du brassage."
},
["mature"] = {
description = "Troisième stade du brassage."
}
}
--------------------------------
function buildRow(argValue, def)
local note = argValue or ''
if note ~= '' then note = LF .. note .. LF end
return mw.html.create( 'li' )
:addClass( 'avt-interactions-row' )
:tag( 'div' )
:addClass( 'avt-interactions-text' )
:tag( 'p' )
:wikitext(def.description)
:done()
:wikitext( note )
:done()
:tag( 'li' )
:wikitext( '[[Fichier:Icon_range_inverse.png|x50px|center]]' )
:done()
end
function p._build(args)
local res = mw.html.create( 'ul' )
:addClass( 'avt-interactions' )
local isEmpty = true
for key, value in pairs(args) do
local def = data[key:lower()]
if def and value ~= '-' and value ~= 'vide' then
isEmpty = false
res:node(buildRow(value, def))
end
end
-- cas particulier l'inventaire du pnj est vide
if isEmpty then
res:node(buildRow(nil, data.vide))
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] = val
end
end
end
return p._build(args)
end
return p