DIV_CLASS_ROW

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


Материал из VEDA Wiki
Перейти к: навигация, поиск
Нет описания правки
Нет описания правки
Метка: отменено
Строка 35: Строка 35:
     local l = {}
     local l = {}
     for k in string.gmatch(i, "[^!]+") do
     for k in string.gmatch(i, "[^!]+") do
       table.insert(l, k)
       table.insert(l, k..' ')
     end
     end



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

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

local p = {} -- p stands for package

function p.synonyms( frame )
  local t = {}
  local name = frame.args[1]
  local listitem = frame.args['listitem'] == 'true' and '<br>' or '; ' -- additional param for items lists
  if #name == 0 then
    return ''
  end

  for i in string.gmatch(name, "[^;]+") do
    table.insert(t, "[[" .. i .. "]]")
  end

  --table.insert(t, ")")
  local out = table.concat(t, listitem)
  if listitem == '; ' then
    out = "(" .. out
    out = out .. ")"
  end
  return out
end

-- prev.version - 2DEL
function p.event_members_2DEL( frame )
  local t = {}
  local name = frame.args[1]
  for i in string.gmatch(name, "[^;]+") do
    local field2 = ''
    local field3 = ''
    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..' ')
    end

    if l[2] == nil or l[2] == '' 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]

    if l[3] == nil or l[3] == '' or l[3] == ' ' then
      field3 = ''
    else
      field3 = [[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Количество:</td>
  <td>]]..l[3]..'</td></tr>'
    end -- if l[3]

    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>'
..
field2
..
field3)

  end -- 'for i' cycle

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

  return table.concat(t, "")
end -- p.event_members_2DEL( frame )

function p.event_members( frame )
  local name = frame.args[1]
  local count = 0 -- computes overall amount of members as 1 per person or as number in 'Количество' field
  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
-- 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 = ''
    local field3 = ''
    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] == nil or l[2] == '' 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]

    if l[3] == nil or l[3] == '' or l[3] == ' ' then
      field3 = ''
      count = count + 1
    else
      field3 = [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Количество:</td>
  <td>]=] .. l[3] .. '</td></tr>'
      count = count + l[3]
    end -- if l[3]

    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 .. field3)

  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 -- p.event_members( frame )

return p