Модуль: Infobox tmp: различия между версиями 🔗


Материал из VEDA Wiki
Перейти к: навигация, поиск
Нет описания правки
Нет описания правки
Строка 30: Строка 30:
     end
     end


if #l[2]<5 and l[2] ~=nil or l[2] ~='' then  
if #l[2]<5 and l[2] ~='' or l[2] ~=nil then  
   table.insert(l, 2, 'XXX')
   table.insert(l, 2, 'XXX')
end
end

Версия от 19:37, 3 октября 2024

Для документации этого модуля может быть создана страница Модуль:Infobox tmp/doc

local p = {} -- p stands for package

function p.organization_members( frame )
  local count = 0
  local name = frame.args[1]
  local t = {[=[<table border=0>
<tr><td colspan=2>
<div {{DivWrapOpts}}>[[Category:WrapBlock]]
<table border=0 width=100%><tr><td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">Лидеры</td></tr></table>
<div class="mw-collapsible-content">
<table border=0>
]=]}

  for i in string.gmatch(name, "[^;]+") do repeat
    count = count + 1
-- continue if line is "empty" (namely is "!!!;" or only ";") see: https://forum.defold.com/t/any-replace-for-continue-statement-in-lua-loops/65554/2
    if #i <6 then
      do break end
    end

    local field2 = ''
    table.insert(t, [=[<tr>
  <td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">Глава</td>
</tr>]=])

    local l = {}
-- Лидер!Профессия!Лидер_с!Лидер_по;
    for k in string.gmatch(i, "[^!]+") do
      table.insert(l, k:match( "^%s*(.-)%s*$" )..' ')
    end

if #l[2]<5 and l[2] ~='' or l[2] ~=nil then 
  table.insert(l, 2, 'XXX')
end

    if l[2] == '' or l[2] == nil or l[2] == ' ' then
      field2 = ''
    else
      field2 = [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Профессия:</td>
  <td>]=] .. l[2] .. '</td></tr>'
    end -- if l[2]

--- time range formatting
    local timerange = ''
    if     (l[3] == nil or l[3] == '' or l[3] == ' ') and (l[4] ~= nil or l[4] ~= '' or l[4] ~= ' ') then
             timerange = 'по ' .. l[4]
    elseif (l[3] ~= nil or l[3] ~= '' or l[3] ~= ' ') and (l[4] == nil or l[4] == '' or l[4] == ' ') then
             timerange = 'с ' .. l[3]
    elseif (l[3] ~= nil or l[3] ~= '' or l[3] ~= ' ') and (l[4] ~= nil or l[4] ~= '' or l[4] ~= ' ') then
             timerange = l[3] .. ' — ' .. l[4]
    else
             timerange = ''
    end

    if timerange ~= '' then
    timerange = [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Даты:</td>
  <td>]=] .. timerange .. '</td></tr>'
    end

    table.insert(t, [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Имя:</td>
  <td>[[]=] .. l[1] .. ']]</td></tr>' .. [=[[[Category:]=] .. l[1] .. [=[]]]=]
.. field2 .. timerange) -- WAS: .. field2 .. field3 .. field4 .. timerange)

  until true end -- 'for i' cycle
      table.insert(t, [=[</table>
</div></div>
</td></tr>
<tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Общее число:</td>
  <td>не менее 
]=] .. count .. '</td></tr>')

  return table.concat(t, "")
end

return p