Mudanças entre as edições de "Módulo:Changelog"

De Wiki Gla
Ir para navegação Ir para pesquisar
(Criou página com '-- Módulo:Changelog — gera HTML do changelog a partir de itemN_* params local p = {} local function getArgs(frame) -- pega args do parent quando chamado via predef loc...')
 
m
Linha 1: Linha 1:
-- Módulo:Changelog — gera HTML do changelog a partir de itemN_* params
-- Módulo:Changelog — renderiza UMA linha do changelog (sem limite de quantidade)
local p = {}
local p = {}


local function getArgs(frame)
local function N(s) return s and mw.text.trim(tostring(s)) or '' end
   -- pega args do parent quando chamado via predef
local function has(s) return N(s) ~= '' end
  local parent = frame:getParent()
local function param(args, ...)
   return parent and parent.args or frame.args
   for i = 1, select('#', ...) do
    local k = select(i, ...)
    if has(args[k]) then return N(args[k]) end
  end
   return ''
end
end


local function isNonEmpty(s)
function p.item(frame)
   return s and tostring(s):match("%S")
   local args = frame:getParent() and frame:getParent().args or frame.args
end


function p.render(frame)
  local title = param(args, 'title','titulo','título')
   local args = getArgs(frame)
  local link  = param(args, 'link','url')
   local root = mw.html.create('div')
   local date  = param(args, 'date','data')
   root:addClass('widget-changelog')
  local desc  = param(args, 'description','desc','descricao','descrição')
   local icon  = param(args, 'icon','icone','ícone','image')
   local color = param(args, 'color','cor')


   -- permite customizar altura máxima via parâmetro (ex.: max_height=320px)
   local item = mw.html.create('div')
  if isNonEmpty(args.max_height) then
     :addClass('notice-item')
     root:css('max-height', args.max_height)
     :css('display','flex')
     -- padding-right opcional
     :css('align-items','flex-start')
    if isNonEmpty(args.padding_right) then
     :css('background','#fff')
      root:css('padding-right', args.padding_right)
    :css('border','1px solid #ddd')
     else
    :css('border-radius','6px')
      root:css('padding-right', '5px')
     :css('margin-bottom','10px')
     end
     :css('padding','8px 10px')
  else
     :css('box-sizing','border-box')
    root:css('padding-right', isNonEmpty(args.padding_right) and args.padding_right or '5px')
     :css('border-left','5px solid var(--notice-color, #f5b700)')
  end
  root:css('overflow-y', 'auto')
  root:css('box-sizing', 'border-box')
 
  local i = 1
  local any = false
 
  while true do
     local title = args['item'..i..'_title']
     local link  = args['item'..i..'_link']
     local date  = args['item'..i..'_date']
     local desc  = args['item'..i..'_desc']
    local color = args['item'..i..'_color'] -- ex: #FCE5CD
    local icon  = args['item'..i..'_icon']  -- URL opcional
 
    if not (isNonEmpty(title) or isNonEmpty(desc) or isNonEmpty(link)) then
      -- se não tem título/desc/link, checa se ainda existe próximo antes de encerrar
      if not (args['item'..(i+1)..'_title'] or args['item'..(i+1)..'_desc'] or args['item'..(i+1)..'_link']) then
        break
      end
    end


    any = true
  if has(color) then item:css('--notice-color', color) end
    local item = root:tag('div'):addClass('notice-item')
    item:css('display', 'flex')
    item:css('align-items', 'flex-start')
    item:css('background', '#fff')
    item:css('border', '1px solid #ddd')
    item:css('border-radius', '6px')
    item:css('margin-bottom', '10px')
    item:css('padding', '8px 10px')
    item:css('box-sizing', 'border-box')
    item:css('border-left', '5px solid var(--notice-color, #f5b700)')
    if isNonEmpty(color) then
      item:css('--notice-color', color)
    end


    local content = item:tag('div'):addClass('notice-content')
  local content = item:tag('div'):addClass('notice-content'):css('flex','1')
    content:css('flex', '1')


     if isNonEmpty(title) then
  if has(title) then
       local a = content:tag('a')
    local titleNode
     if has(link) then
       titleNode = content:tag('a')
         :addClass('notice-title')
         :addClass('notice-title')
         :attr('target', '_blank')
         :attr('href', link):attr('target','_blank')
      if isNonEmpty(link) then a:attr('href', link) end
        :css('text-decoration','none')
      a:css('display', 'block')
    else
      a:css('font-size', '1.3em')
       titleNode = content:tag('span'):addClass('notice-title')
      a:css('font-weight', 'bold')
       a:css('color', '#333')
      a:css('text-decoration', 'none')
      a:css('margin', '0')
      a:wikitext(title)
     end
     end
    titleNode
      :css('display','block')
      :css('font-size','1.3em')
      :css('font-weight','bold')
      :css('color','#333')
      :css('margin','0')
      :wikitext(title)
  end


    if isNonEmpty(date) then
  if has(date) then
      content:tag('div')
    content:tag('div')
        :addClass('notice-date')
      :addClass('notice-date')
        :css('font-size', '0.9em')
      :css('font-size','0.9em')
        :css('color', '#888')
      :css('color','#888')
        :css('margin', '-5px 0')
      :css('margin','-5px 0')
        :wikitext(date)
      :wikitext(date)
    end
  end
 
    if isNonEmpty(desc) then
      content:tag('p')
        :addClass('notice-desc')
        :css('color', '#555')
        :css('line-height', '1.3')
        :css('margin', '0')
        :wikitext(desc)
    end
 
    if isNonEmpty(icon) then
      item:tag('img')
        :addClass('notice-icon')
        :attr('src', icon)
        :css('object-fit', 'contain')
        :css('flex-shrink', '0')
        -- sem width/height fixos: respeita o asset do jeito que você já usa
    end


     i = i + 1
  if has(desc) then
     content:tag('p')
      :addClass('notice-desc')
      :css('color','#555')
      :css('line-height','1.3')
      :css('margin','0')
      :wikitext(desc)
   end
   end


   if not any then
   if has(icon) then
     -- fallback minimalista
     item:tag('img')
    root:tag('div')
      :addClass('notice-icon')
       :css('color', '#666')
      :attr('src', icon)
       :wikitext('Sem atualizações no momento.')
      :attr('alt', title or '')
       :css('object-fit','contain')
       :css('flex-shrink','0')
   end
   end


   return tostring(root)
   return tostring(item)
end
end


return p
return p

Edição das 18h21min de 2 de setembro de 2025

A documentação para este módulo pode ser criada em Módulo:Changelog/doc

-- Módulo:Changelog — renderiza UMA linha do changelog (sem limite de quantidade)
local p = {}

local function N(s) return s and mw.text.trim(tostring(s)) or '' end
local function has(s) return N(s) ~= '' end
local function param(args, ...)
  for i = 1, select('#', ...) do
    local k = select(i, ...)
    if has(args[k]) then return N(args[k]) end
  end
  return ''
end

function p.item(frame)
  local args = frame:getParent() and frame:getParent().args or frame.args

  local title = param(args, 'title','titulo','título')
  local link  = param(args, 'link','url')
  local date  = param(args, 'date','data')
  local desc  = param(args, 'description','desc','descricao','descrição')
  local icon  = param(args, 'icon','icone','ícone','image')
  local color = param(args, 'color','cor')

  local item = mw.html.create('div')
    :addClass('notice-item')
    :css('display','flex')
    :css('align-items','flex-start')
    :css('background','#fff')
    :css('border','1px solid #ddd')
    :css('border-radius','6px')
    :css('margin-bottom','10px')
    :css('padding','8px 10px')
    :css('box-sizing','border-box')
    :css('border-left','5px solid var(--notice-color, #f5b700)')

  if has(color) then item:css('--notice-color', color) end

  local content = item:tag('div'):addClass('notice-content'):css('flex','1')

  if has(title) then
    local titleNode
    if has(link) then
      titleNode = content:tag('a')
        :addClass('notice-title')
        :attr('href', link):attr('target','_blank')
        :css('text-decoration','none')
    else
      titleNode = content:tag('span'):addClass('notice-title')
    end
    titleNode
      :css('display','block')
      :css('font-size','1.3em')
      :css('font-weight','bold')
      :css('color','#333')
      :css('margin','0')
      :wikitext(title)
  end

  if has(date) then
    content:tag('div')
      :addClass('notice-date')
      :css('font-size','0.9em')
      :css('color','#888')
      :css('margin','-5px 0')
      :wikitext(date)
  end

  if has(desc) then
    content:tag('p')
      :addClass('notice-desc')
      :css('color','#555')
      :css('line-height','1.3')
      :css('margin','0')
      :wikitext(desc)
  end

  if has(icon) then
    item:tag('img')
      :addClass('notice-icon')
      :attr('src', icon)
      :attr('alt', title or '')
      :css('object-fit','contain')
      :css('flex-shrink','0')
  end

  return tostring(item)
end

return p