Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« Module:Roadmap » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Page créée avec « -- ============================================================ -- Module:Roadmap -- Génère une roadmap visuelle pour wiki.nefald.fr -- ============================================================ local p = {} -- ------------------------------------------------------------ -- CONFIGURATION CENTRALE -- Modifie ici les statuts, couleurs, icônes et tags -- ------------------------------------------------------------ local CONFIG = { statuts = { done = {... »
 
Hiob (discussion | contributions)
Aucun résumé des modifications
 
(7 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :
-- Module:Roadmap
-- Module:Roadmap
-- Génère une roadmap visuelle pour wiki.nefald.fr
-- Génère une roadmap visuelle pour wiki.nefald.fr
-- Intégré au design system Citizen
-- ============================================================
-- ============================================================


Ligne 7 : Ligne 8 :


-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- CONFIGURATION CENTRALE
-- CONFIGURATION
-- Modifie ici les statuts, couleurs, icônes et tags
-- ------------------------------------------------------------
-- ------------------------------------------------------------


local CONFIG = {
local CONFIG = {
 
statuts = {
  statuts = {
done = {
    done = {
label = "Terminé",
      label   = "Terminé",
icon = "✓",
      icon   = "✓",
order = 1,
      color  = "#27ae60",
},
      order   = 1,   -- ordre d'affichage si tri activé
inprogress = {
    },
label = "En cours",
    inprogress = {
icon = "◉",
      label   = "En cours",
order = 2,
      icon   = "◉",
},
      color  = "#f39c12",
planned = {
      order   = 2,
label = "Planifié",
    },
icon = "○",
    planned = {
order = 3,
      label   = "Planifié",
},
      icon   = "○",
idea = {
      color  = "#3498db",
label = "Idée",
      order   = 3,
icon = "✦",
    },
order = 4,
    idea = {
},
      label   = "Idée",
cancelled = {
      icon   = "✦",
label = "Annulé",
      color  = "#9b59b6",
icon = "✕",
      order   = 4,
order = 5,
    },
},
    cancelled = {
},
      label   = "Annulé",
done_statuts   = { done = true },
      icon   = "✕",
ignored_statuts = { cancelled = true },
      color  = "#e74c3c",
      order   = 5,
    },
  },
 
  -- Tags disponibles : nom = couleur de fond, couleur texte
  tags = {
    gameplay  = { bg = "#d5f5e3", fg = "#1e8449" },
    technique = { bg = "#d6eaf8", fg = "#1a5276" },
    contenu  = { bg = "#fdebd0", fg = "#784212" },
    interface = { bg = "#f9ebea", fg = "#922b21" },
    event    = { bg = "#f5eef8", fg = "#6c3483" },
    wiki      = { bg = "#eafaf1", fg = "#1d6a39" },
    discord  = { bg = "#eee8ff", fg = "#4527a0" },
  },
 
  -- Statuts comptabilisés comme "terminés" pour la progression
  done_statuts = { done = true },
 
  -- Statuts ignorés dans le calcul de progression
  ignored_statuts = { cancelled = true },
}
}


Ligne 68 : Ligne 47 :
-- ------------------------------------------------------------
-- ------------------------------------------------------------


-- Échappe le HTML pour éviter les injections
local function escapeHtml(s)
local function escapeHtml(s)
  if not s then return "" end
if not s then return "" end
  s = tostring(s)
s = tostring(s)
  s = s:gsub("&", "&")
s = s:gsub("&", "&")
  s = s:gsub("<", "&lt;")
s = s:gsub("<", "&lt;")
  s = s:gsub(">", "&gt;")
s = s:gsub(">", "&gt;")
  s = s:gsub('"', "&quot;")
s = s:gsub('"', "&quot;")
  return s
return s
end
end


-- Trim des espaces
local function trim(s)
local function trim(s)
  if not s then return "" end
if not s then return "" end
  return s:match("^%s*(.-)%s*$")
return s:match("^%s*(.-)%s*$")
end
end


-- Récupère un paramètre nommé ou positionnel avec fallback
local function getParam(args, ...)
local function getParam(args, ...)
  for _, key in ipairs({...}) do
for _, key in ipairs({...}) do
    local v = trim(args[key] or "")
local v = trim(args[key] or "")
    if v ~= "" then return v end
if v ~= "" then return v end
  end
end
  return nil
return nil
end
 
local function sanitizeClass(s)
if not s then return "" end
s = s:lower()
s = s:gsub("[^%w%-]", "")
return s
end
end


-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- PARSEUR DE SECTIONS ET ITEMS
-- PARSEUR (séparateur ;; au lieu de |)
-- Lit le contenu brut du template et extrait les données
-- ------------------------------------------------------------
-- ------------------------------------------------------------
--[[
  Format attendu dans le wikitext :
 
  == Titre de section ==
  item | statut | Titre | desc=Description | tag=gameplay | date=Jan 2025
  item | done  | Truc  | tag=wiki
 
  Chaque ligne "item" devient un item de roadmap.
  Les lignes "==" deviennent des sections.
]]


local function parseContenu(raw)
local function parseContenu(raw)
  local elements = {}
local elements = {}
 
for line in (raw .. "\n"):gmatch("([^\n]*)\n") do
  for line in (raw .. "\n"):gmatch("([^\n]*)\n") do
line = trim(line)
    line = trim(line)
if line == "" or line:match("^%-%-") then
 
-- skip
    -- Ignorer les lignes vides et commentaires
elseif line:match("^@section%s+") then
    if line == "" or line:match("^%-%-") then
local titre = line:match("^@section%s+(.+)$")
      -- skip
table.insert(elements, {
 
type  = "section",
    -- Détecter une section : == Titre ==
titre = trim(titre or "Section"),
    elseif line:match("^==.+==$") then
})
      local titre = line:match("^==%s*(.-)%s*==$")
elseif line:match("^item%s*;;") then
      table.insert(elements, {
local parts = {}
        type  = "section",
for part in (line .. ";;"):gmatch("(.-);;") do
        titre = titre or "Section",
table.insert(parts, trim(part))
      })
end
 
-- parts[1] = "item", parts[2] = statut, parts[3] = titre, etc.
    -- Détecter un item : item | statut | Titre | ...
local statut = trim(parts[2] or "planned"):lower()
    elseif line:match("^item%s*|") or line:match("^item%s*:") then
local titre  = trim(parts[3] or "")
      -- Séparer par "|"
local item = {
      local parts = {}
type  = "item",
      for part in line:gmatch("([^|]+)") do
statut = CONFIG.statuts[statut] and statut or "planned",
        table.insert(parts, trim(part))
titre  = titre,
      end
desc  = nil,
      -- parts[1] = "item", parts[2] = statut, parts[3] = titre, parts[4..n] = params
tags  = {},
 
date  = nil,
      local statut = trim(parts[2] or "planned"):lower()
lien  = nil,
      local titre  = trim(parts[3] or "")
}
      local item   = {
for i = 4, #parts do
        type  = "item",
local key, val = parts[i]:match("^(%w+)%s*=%s*(.+)$")
        statut = CONFIG.statuts[statut] and statut or "planned",
if key and val then
        titre  = titre,
key = key:lower()
        desc  = nil,
if key == "desc" then
        tags  = {},
item.desc = val
        date  = nil,
elseif key == "tag" or key == "tags" then
        lien  = nil,
for tag in val:gmatch("([^,]+)") do
      }
table.insert(item.tags, trim(tag):lower())
 
end
      -- Parser les paramètres nommés dans parts[4..n]
elseif key == "date" then
      for i = 4, #parts do
item.date = val
        local key, val = parts[i]:match("^(%w+)%s*=%s*(.+)$")
elseif key == "lien" then
        if key and val then
item.lien = val
          key = key:lower()
end
          if key == "desc" then
end
            item.desc = val
end
          elseif key == "tag" or key == "tags" then
table.insert(elements, item)
            -- Support multi-tags séparés par virgule
end
            for tag in val:gmatch("([^,]+)") do
end
              table.insert(item.tags, trim(tag):lower())
return elements
            end
          elseif key == "date" then
            item.date = val
          elseif key == "lien" then
            item.lien = val
          end
        end
      end
 
      table.insert(elements, item)
    end
  end
 
  return elements
end
end


-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- CALCUL DE LA PROGRESSION
-- CALCUL PROGRESSION
-- ------------------------------------------------------------
-- ------------------------------------------------------------


local function calcProgression(elements)
local function calcProgression(elements)
  local total = 0
local total = 0
  local done  = 0
local done  = 0
 
for _, el in ipairs(elements) do
  for _, el in ipairs(elements) do
if el.type == "item" then
    if el.type == "item" then
if not CONFIG.ignored_statuts[el.statut] then
      if not CONFIG.ignored_statuts[el.statut] then
total = total + 1
        total = total + 1
if CONFIG.done_statuts[el.statut] then
        if CONFIG.done_statuts[el.statut] then
done = done + 1
          done = done + 1
end
        end
end
      end
end
    end
end
  end
if total == 0 then return 0, 0, 0 end
 
return math.floor((done / total) * 100), done, total
  if total == 0 then return 0, 0, 0 end
  local pct = math.floor((done / total) * 100)
  return pct, done, total
end
end


Ligne 205 : Ligne 159 :


local function htmlBadge(statut)
local function htmlBadge(statut)
  local s = CONFIG.statuts[statut] or CONFIG.statuts.planned
local s = CONFIG.statuts[statut] or CONFIG.statuts.planned
  return string.format(
return string.format(
    '<span class="roadmap-badge" style="background:%s" title="%s">%s</span>',
'<span class="roadmap-badge roadmap-badge-%s" title="%s">%s</span>',
    s.color,
statut, escapeHtml(s.label), s.icon
    escapeHtml(s.label),
)
    s.icon
  )
end
end


local function htmlTags(tags)
local function htmlTags(tags)
  if not tags or #tags == 0 then return "" end
if not tags or #tags == 0 then return "" end
  local parts = {}
local parts = {}
  for _, tag in ipairs(tags) do
for _, tag in ipairs(tags) do
    local cfg = CONFIG.tags[tag]
table.insert(parts, string.format(
    if cfg then
'<span class="roadmap-tag roadmap-tag-%s">%s</span>',
      table.insert(parts, string.format(
sanitizeClass(tag), escapeHtml(tag)
        '<span class="roadmap-tag" style="background:%s;color:%s">%s</span>',
))
        cfg.bg, cfg.fg, escapeHtml(tag)
end
      ))
return '<div class="roadmap-tags">' .. table.concat(parts) .. '</div>'
    else
      -- Tag inconnu : style neutre
      table.insert(parts, string.format(
        '<span class="roadmap-tag">%s</span>',
        escapeHtml(tag)
      ))
    end
  end
  return '<div class="roadmap-tags">' .. table.concat(parts) .. '</div>'
end
end


local function htmlItem(item)
local function htmlItem(item)
  local statut = item.statut or "planned"
local statut = item.statut or "planned"
  local titreTxt = escapeHtml(item.titre)
local titreTxt = escapeHtml(item.titre)
 
local titreHtml
  -- Lien sur le titre si défini
if item.lien and item.lien ~= "" then
  local titreHtml
titreHtml = string.format('<a href="%s">%s</a>', escapeHtml(item.lien), titreTxt)
  if item.lien and item.lien ~= "" then
else
    titreHtml = string.format(
titreHtml = titreTxt
      '<a href="%s">%s</a>',
end
      escapeHtml(item.lien), titreTxt
local descHtml = ""
    )
if item.desc and item.desc ~= "" then
  else
descHtml = string.format(
    titreHtml = titreTxt
'<div class="roadmap-item-desc">%s</div>',
  end
escapeHtml(item.desc)
 
)
  local descHtml = ""
end
  if item.desc and item.desc ~= "" then
local dateHtml = ""
    descHtml = string.format(
if item.date and item.date ~= "" then
      '<div class="roadmap-item-desc">%s</div>',
dateHtml = string.format(
      escapeHtml(item.desc)
'<div class="roadmap-date">%s</div>',
    )
escapeHtml(item.date)
  end
)
 
end
  local dateHtml = ""
return string.format(
  if item.date and item.date ~= "" then
'<div class="roadmap-item roadmap-%s">'
    dateHtml = string.format(
.. '%s'
      '<div class="roadmap-date">%s</div>',
.. '<div class="roadmap-item-content">'
      escapeHtml(item.date)
.. '<div class="roadmap-item-title">%s</div>'
    )
.. '%s%s'
  end
.. '</div>'
 
.. '%s'
  return string.format(
.. '</div>',
    '<div class="roadmap-item roadmap-%s">%s<div class="roadmap-item-content"><div class="roadmap-item-title">%s</div>%s%s</div>%s</div>',
statut, htmlBadge(statut), titreHtml, descHtml, htmlTags(item.tags), dateHtml
    statut,
)
    htmlBadge(statut),
    titreHtml,
    descHtml,
    htmlTags(item.tags),
    dateHtml
  )
end
end


local function htmlSection(section)
local function htmlSection(section)
  return string.format(
return string.format(
    '<div class="roadmap-section"><div class="roadmap-section-title">%s</div>',
'<div class="roadmap-section"><div class="roadmap-section-title">%s</div>',
    escapeHtml(section.titre)
escapeHtml(section.titre)
  )
)
end
end


local function htmlProgressBar(pct, done, total)
local function htmlProgressBar(pct, done, total)
  return string.format(
return string.format(
    '<div class="roadmap-progress-wrap">' ..
'<div class="roadmap-progress-wrap">'
    '<div class="roadmap-progress-label">Progression : <strong>%d%%</strong> &mdash; %d / %d fonctionnalités terminées</div>' ..
.. '<div class="roadmap-progress-label">'
    '<div class="roadmap-progress-bar"><div class="roadmap-progress-fill" style="width:%d%%"></div></div>' ..
.. 'Progression\194\160: <strong>%d%%</strong> %d / %d fonctionnalités'
    '</div>',
.. '</div>'
    pct, done, total, pct
.. '<div class="roadmap-progress-bar">'
  )
.. '<div class="roadmap-progress-fill" style="width:%d%%"></div>'
.. '</div>'
.. '</div>',
pct, done, total, pct
)
end
end


local function htmlLegende()
local function htmlLegende()
  local parts = {}
local parts = {}
  -- Ordre d'affichage fixé
local ordre = { "done", "inprogress", "planned", "idea", "cancelled" }
  local ordre = { "done", "inprogress", "planned", "idea", "cancelled" }
for _, key in ipairs(ordre) do
  for _, key in ipairs(ordre) do
local s = CONFIG.statuts[key]
    local s = CONFIG.statuts[key]
if s then
    if s then
table.insert(parts, string.format(
      table.insert(parts, string.format(
'<span class="roadmap-legend-item roadmap-%s">'
        '<span class="roadmap-legend-item">' ..
.. '%s %s</span>',
        '<span class="roadmap-badge" style="background:%s;width:18px;height:18px;font-size:0.75em">%s</span>' ..
key, htmlBadge(key), escapeHtml(s.label)
        ' %s</span>',
))
        s.color, s.icon, escapeHtml(s.label)
end
      ))
end
    end
return '<div class="roadmap-legend">' .. table.concat(parts, "") .. '</div>'
  end
  return '<div class="roadmap-legend">' .. table.concat(parts, "") .. '</div>'
end
end


local function htmlStats(elements)
local function htmlStats(elements)
  -- Compte par statut
local counts = { done = 0, inprogress = 0, planned = 0, idea = 0, cancelled = 0 }
  local counts = {}
for _, el in ipairs(elements) do
  for key in pairs(CONFIG.statuts) do counts[key] = 0 end
if el.type == "item" and counts[el.statut] then
 
counts[el.statut] = counts[el.statut] + 1
  for _, el in ipairs(elements) do
end
    if el.type == "item" and counts[el.statut] then
end
      counts[el.statut] = counts[el.statut] + 1
local order = {
    end
{ key = "done",       label = "Terminé" },
  end
{ key = "inprogress", label = "En cours" },
 
{ key = "planned",   label = "Planifié" },
  local parts = {}
{ key = "idea",       label = "Idée" },
  local ordre = { "done", "inprogress", "planned", "idea", "cancelled" }
{ key = "cancelled",  label = "Annulé" },
  for _, key in ipairs(ordre) do
}
    if counts[key] and counts[key] > 0 then
local parts = { '<div class="roadmap-stats">' }
      local s = CONFIG.statuts[key]
for _, s in ipairs(order) do
      table.insert(parts, string.format(
if counts[s.key] > 0 then
        '<span class="roadmap-stat" style="border-color:%s">' ..
table.insert(parts, string.format(
        '<span class="roadmap-stat-count" style="color:%s">%d</span>' ..
'<div class="roadmap-stat roadmap-stat-%s">'
        '<span class="roadmap-stat-label">%s</span>' ..
.. '<span class="roadmap-stat-count">%d</span>'
        '</span>',
.. '<span class="roadmap-stat-label">%s</span>'
        s.color, s.color, counts[key], escapeHtml(s.label)
.. '</div>',
      ))
s.key, counts[s.key], s.label
    end
))
  end
end
 
end
  return '<div class="roadmap-stats">' .. table.concat(parts, "") .. '</div>'
table.insert(parts, '</div>')
return table.concat(parts, "\n")
end
end


-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- POINT D'ENTRÉE PRINCIPAL : render
-- RENDU PRINCIPAL
-- ------------------------------------------------------------
-- ------------------------------------------------------------


function p.render(frame)
function p.render(frame)
  local args   = frame:getParent().args
local args = frame:getParent().args
  local titre  = getParam(args, "titre")  or "Roadmap"
local rawContenu = trim(args["contenu"] or args[1] or "")
  local subtitle = getParam(args, "subtitle")
--
  local rawContenu = trim(args[1] or args["contenu"] or "")
local titre    = getParam(args, "titre", "title") or "Roadmap"
  local showStats  = getParam(args, "stats") ~= "non"
local subtitle = getParam(args, "subtitle")
  local showLegende = getParam(args, "legende") ~= "non"
--
 
local elements = parseContenu(rawContenu)
  -- Parsing du contenu
local pct, done, total = calcProgression(elements)
  local elements = parseContenu(rawContenu)
--
 
local out = {}
  -- Calcul automatique de la progression
table.insert(out, '<div class="roadmap-container">')
  local pct, done, total = calcProgression(elements)
-- En-tête
 
table.insert(out, '<div class="roadmap-header">')
  -- Construction du HTML
table.insert(out, string.format('<div class="roadmap-title">%s</div>', escapeHtml(titre)))
  local html = {}
if subtitle then
 
table.insert(out, string.format('<div class="roadmap-subtitle">%s</div>', escapeHtml(subtitle)))
  -- Conteneur principal
end
  table.insert(html, '<div class="roadmap-container">')
table.insert(out, htmlProgressBar(pct, done, total))
 
table.insert(out, htmlStats(elements))
  -- Header
table.insert(out, htmlLegende())
  table.insert(html, '<div class="roadmap-header">')
table.insert(out, '</div>')
  table.insert(html, string.format('<div class="roadmap-header-title">%s</div>', escapeHtml(titre)))
-- Corps
  if subtitle then
local sectionOpen = false
    table.insert(html, string.format('<div class="roadmap-subtitle">%s</div>', escapeHtml(subtitle)))
for _, el in ipairs(elements) do
  end
if el.type == "section" then
  table.insert(html, '</div>')
if sectionOpen then
 
table.insert(out, '</div>')
  -- Stats globales
end
  if showStats and #elements > 0 then
table.insert(out, htmlSection(el))
    table.insert(html, htmlStats(elements))
sectionOpen = true
  end
elseif el.type == "item" then
 
table.insert(out, htmlItem(el))
  -- Barre de progression
end
  if total > 0 then
end
    table.insert(html, htmlProgressBar(pct, done, total))
if sectionOpen then
  end
table.insert(out, '</div>')
 
end
  -- Contenu : sections et items
table.insert(out, '</div>')
  local inSection = false
return table.concat(out, "\n")
  for _, el in ipairs(elements) do
    if el.type == "section" then
      if inSection then
        table.insert(html, '</div>') -- ferme section précédente
      end
      table.insert(html, htmlSection(el))
      inSection = true
    elseif el.type == "item" then
      table.insert(html, htmlItem(el))
    end
  end
  if inSection then
    table.insert(html, '</div>') -- ferme dernière section
  end
 
  -- Légende
  if showLegende then
    table.insert(html, htmlLegende())
  end
 
  table.insert(html, '</div>') -- ferme roadmap-container
 
  return table.concat(html, "\n")
end
end


-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- POINT D'ENTRÉE SECONDAIRE : item inline
-- ITEM INLINE
-- Usage : {{#invoke:Roadmap|item|done|Titre|desc=...|tag=...}}
-- ------------------------------------------------------------
-- ------------------------------------------------------------


function p.item(frame)
function p.item(frame)
  local args   = frame.args
local args = frame.args
  local statut = trim(args[1] or "planned"):lower()
local statut = trim(args[1] or "planned"):lower()
  local titre = trim(args[2] or "")
local titre = trim(args[2] or "")
 
if not CONFIG.statuts[statut] then statut = "planned" end
  if not CONFIG.statuts[statut] then statut = "planned" end
local item = {
 
statut = statut,
  local item = {
titre  = titre,
    statut = statut,
desc  = getParam(args, "desc"),
    titre  = titre,
date  = getParam(args, "date"),
    desc  = getParam(args, "desc"),
lien  = getParam(args, "lien"),
    date  = getParam(args, "date"),
tags  = {},
    lien  = getParam(args, "lien"),
}
    tags  = {},
local tagStr = getParam(args, "tag", "tags")
  }
if tagStr then
 
for tag in tagStr:gmatch("([^,]+)") do
  local tagStr = getParam(args, "tag", "tags")
table.insert(item.tags, trim(tag):lower())
  if tagStr then
end
    for tag in tagStr:gmatch("([^,]+)") do
end
      table.insert(item.tags, trim(tag):lower())
return htmlItem(item)
    end
  end
 
  return htmlItem(item)
end
end


return p
return p

Dernière version du 20 février 2026 à 23:07

La documentation pour ce module peut être créée à Module:Roadmap/doc

-- ============================================================
-- Module:Roadmap
-- Génère une roadmap visuelle pour wiki.nefald.fr
-- Intégré au design system Citizen
-- ============================================================

local p = {}

-- ------------------------------------------------------------
-- CONFIGURATION
-- ------------------------------------------------------------

local CONFIG = {
statuts = {
done = {
label = "Terminé",
icon  = "✓",
order = 1,
},
inprogress = {
label = "En cours",
icon  = "◉",
order = 2,
},
planned = {
label = "Planifié",
icon  = "○",
order = 3,
},
idea = {
label = "Idée",
icon  = "✦",
order = 4,
},
cancelled = {
label = "Annulé",
icon  = "✕",
order = 5,
},
},
done_statuts    = { done = true },
ignored_statuts = { cancelled = true },
}

-- ------------------------------------------------------------
-- UTILITAIRES
-- ------------------------------------------------------------

local function escapeHtml(s)
if not s then return "" end
s = tostring(s)
s = s:gsub("&", "&amp;")
s = s:gsub("<", "&lt;")
s = s:gsub(">", "&gt;")
s = s:gsub('"', "&quot;")
return s
end

local function trim(s)
if not s then return "" end
return s:match("^%s*(.-)%s*$")
end

local function getParam(args, ...)
for _, key in ipairs({...}) do
local v = trim(args[key] or "")
if v ~= "" then return v end
end
return nil
end

local function sanitizeClass(s)
if not s then return "" end
s = s:lower()
s = s:gsub("[^%w%-]", "")
return s
end

-- ------------------------------------------------------------
-- PARSEUR (séparateur ;; au lieu de |)
-- ------------------------------------------------------------

local function parseContenu(raw)
local elements = {}
for line in (raw .. "\n"):gmatch("([^\n]*)\n") do
line = trim(line)
if line == "" or line:match("^%-%-") then
-- skip
elseif line:match("^@section%s+") then
local titre = line:match("^@section%s+(.+)$")
table.insert(elements, {
type  = "section",
titre = trim(titre or "Section"),
})
elseif line:match("^item%s*;;") then
local parts = {}
for part in (line .. ";;"):gmatch("(.-);;") do
table.insert(parts, trim(part))
end
-- parts[1] = "item", parts[2] = statut, parts[3] = titre, etc.
local statut = trim(parts[2] or "planned"):lower()
local titre  = trim(parts[3] or "")
local item = {
type   = "item",
statut = CONFIG.statuts[statut] and statut or "planned",
titre  = titre,
desc   = nil,
tags   = {},
date   = nil,
lien   = nil,
}
for i = 4, #parts do
local key, val = parts[i]:match("^(%w+)%s*=%s*(.+)$")
if key and val then
key = key:lower()
if key == "desc" then
item.desc = val
elseif key == "tag" or key == "tags" then
for tag in val:gmatch("([^,]+)") do
table.insert(item.tags, trim(tag):lower())
end
elseif key == "date" then
item.date = val
elseif key == "lien" then
item.lien = val
end
end
end
table.insert(elements, item)
end
end
return elements
end

-- ------------------------------------------------------------
-- CALCUL PROGRESSION
-- ------------------------------------------------------------

local function calcProgression(elements)
local total = 0
local done  = 0
for _, el in ipairs(elements) do
if el.type == "item" then
if not CONFIG.ignored_statuts[el.statut] then
total = total + 1
if CONFIG.done_statuts[el.statut] then
done = done + 1
end
end
end
end
if total == 0 then return 0, 0, 0 end
return math.floor((done / total) * 100), done, total
end

-- ------------------------------------------------------------
-- GÉNÉRATEURS HTML
-- ------------------------------------------------------------

local function htmlBadge(statut)
local s = CONFIG.statuts[statut] or CONFIG.statuts.planned
return string.format(
'<span class="roadmap-badge roadmap-badge-%s" title="%s">%s</span>',
statut, escapeHtml(s.label), s.icon
)
end

local function htmlTags(tags)
if not tags or #tags == 0 then return "" end
local parts = {}
for _, tag in ipairs(tags) do
table.insert(parts, string.format(
'<span class="roadmap-tag roadmap-tag-%s">%s</span>',
sanitizeClass(tag), escapeHtml(tag)
))
end
return '<div class="roadmap-tags">' .. table.concat(parts) .. '</div>'
end

local function htmlItem(item)
local statut = item.statut or "planned"
local titreTxt = escapeHtml(item.titre)
local titreHtml
if item.lien and item.lien ~= "" then
titreHtml = string.format('<a href="%s">%s</a>', escapeHtml(item.lien), titreTxt)
else
titreHtml = titreTxt
end
local descHtml = ""
if item.desc and item.desc ~= "" then
descHtml = string.format(
'<div class="roadmap-item-desc">%s</div>',
escapeHtml(item.desc)
)
end
local dateHtml = ""
if item.date and item.date ~= "" then
dateHtml = string.format(
'<div class="roadmap-date">%s</div>',
escapeHtml(item.date)
)
end
return string.format(
'<div class="roadmap-item roadmap-%s">'
.. '%s'
.. '<div class="roadmap-item-content">'
.. '<div class="roadmap-item-title">%s</div>'
.. '%s%s'
.. '</div>'
.. '%s'
.. '</div>',
statut, htmlBadge(statut), titreHtml, descHtml, htmlTags(item.tags), dateHtml
)
end

local function htmlSection(section)
return string.format(
'<div class="roadmap-section"><div class="roadmap-section-title">%s</div>',
escapeHtml(section.titre)
)
end

local function htmlProgressBar(pct, done, total)
return string.format(
'<div class="roadmap-progress-wrap">'
.. '<div class="roadmap-progress-label">'
.. 'Progression\194\160: <strong>%d%%</strong> — %d / %d fonctionnalités'
.. '</div>'
.. '<div class="roadmap-progress-bar">'
.. '<div class="roadmap-progress-fill" style="width:%d%%"></div>'
.. '</div>'
.. '</div>',
pct, done, total, pct
)
end

local function htmlLegende()
local parts = {}
local ordre = { "done", "inprogress", "planned", "idea", "cancelled" }
for _, key in ipairs(ordre) do
local s = CONFIG.statuts[key]
if s then
table.insert(parts, string.format(
'<span class="roadmap-legend-item roadmap-%s">'
.. '%s %s</span>',
key, htmlBadge(key), escapeHtml(s.label)
))
end
end
return '<div class="roadmap-legend">' .. table.concat(parts, "") .. '</div>'
end

local function htmlStats(elements)
local counts = { done = 0, inprogress = 0, planned = 0, idea = 0, cancelled = 0 }
for _, el in ipairs(elements) do
if el.type == "item" and counts[el.statut] then
counts[el.statut] = counts[el.statut] + 1
end
end
local order = {
{ key = "done",       label = "Terminé" },
{ key = "inprogress", label = "En cours" },
{ key = "planned",    label = "Planifié" },
{ key = "idea",       label = "Idée" },
{ key = "cancelled",  label = "Annulé" },
}
local parts = { '<div class="roadmap-stats">' }
for _, s in ipairs(order) do
if counts[s.key] > 0 then
table.insert(parts, string.format(
'<div class="roadmap-stat roadmap-stat-%s">'
.. '<span class="roadmap-stat-count">%d</span>'
.. '<span class="roadmap-stat-label">%s</span>'
.. '</div>',
s.key, counts[s.key], s.label
))
end
end
table.insert(parts, '</div>')
return table.concat(parts, "\n")
end

-- ------------------------------------------------------------
-- RENDU PRINCIPAL
-- ------------------------------------------------------------

function p.render(frame)
local args = frame:getParent().args
local rawContenu = trim(args["contenu"] or args[1] or "")
--
local titre    = getParam(args, "titre", "title") or "Roadmap"
local subtitle = getParam(args, "subtitle")
--
local elements = parseContenu(rawContenu)
local pct, done, total = calcProgression(elements)
--
local out = {}
table.insert(out, '<div class="roadmap-container">')
-- En-tête
table.insert(out, '<div class="roadmap-header">')
table.insert(out, string.format('<div class="roadmap-title">%s</div>', escapeHtml(titre)))
if subtitle then
table.insert(out, string.format('<div class="roadmap-subtitle">%s</div>', escapeHtml(subtitle)))
end
table.insert(out, htmlProgressBar(pct, done, total))
table.insert(out, htmlStats(elements))
table.insert(out, htmlLegende())
table.insert(out, '</div>')
-- Corps
local sectionOpen = false
for _, el in ipairs(elements) do
if el.type == "section" then
if sectionOpen then
table.insert(out, '</div>')
end
table.insert(out, htmlSection(el))
sectionOpen = true
elseif el.type == "item" then
table.insert(out, htmlItem(el))
end
end
if sectionOpen then
table.insert(out, '</div>')
end
table.insert(out, '</div>')
return table.concat(out, "\n")
end

-- ------------------------------------------------------------
-- ITEM INLINE
-- ------------------------------------------------------------

function p.item(frame)
local args = frame.args
local statut = trim(args[1] or "planned"):lower()
local titre = trim(args[2] or "")
if not CONFIG.statuts[statut] then statut = "planned" end
local item = {
statut = statut,
titre  = titre,
desc   = getParam(args, "desc"),
date   = getParam(args, "date"),
lien   = getParam(args, "lien"),
tags   = {},
}
local tagStr = getParam(args, "tag", "tags")
if tagStr then
for tag in tagStr:gmatch("([^,]+)") do
table.insert(item.tags, trim(tag):lower())
end
end
return htmlItem(item)
end

return p
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.