Модуль:Навигация: различия между версиями
Перейти к навигации
Перейти к поиску
ЗаяцВолк (обсуждение | вклад) |
ЗаяцВолк (обсуждение | вклад) |
||
Строка 10: | Строка 10: | ||
if args[pos+1] == nil then return end | if args[pos+1] == nil then return end | ||
row["list_v"]=args[pos+1] | row["list_v"]=args[pos+1] | ||
row["style_l"]='width:100%;' | |||
row["n"]=1 | row["n"]=1 | ||
pos=pos+2 | pos=pos+2 | ||
Строка 17: | Строка 18: | ||
if args[pos+1] == nil then return end | if args[pos+1] == nil then return end | ||
row["head_v"]=args[pos+1] | row["head_v"]=args[pos+1] | ||
row["style_h"]='white-space:nowrap;' | |||
pos=pos+2 | pos=pos+2 | ||
if args[pos] == "list" then | if args[pos] == "list" then | ||
Строка 37: | Строка 39: | ||
for i in ipairs (t) do | for i in ipairs (t) do | ||
if t[i]["n"]==2 then | if t[i]["n"]==2 then | ||
result=result..'<tr><td>'..t[i]["head_v"]..'</td><td>'..t[i]["list_v"]..'</td></tr>' | result=result..'<tr><td style="'..t[i]["style_h"]..'" >'..t[i]["head_v"]..'</td><td>'..t[i]["list_v"]..'</td></tr>' | ||
else | else | ||
if t[i]["head_v"] ~= nil then | if t[i]["head_v"] ~= nil then |
Версия 10:37, 18 июля 2024
Для документации этого модуля может быть создана страница Модуль:Навигация/doc
local text="" local pos=1 -- итерируемая позиция в разбираемом шаблоне local args = {} -- элементы шаблона -- эти 2 переменные можно всунуть внутрь функций local t = {} -- таблица данных для создания шаблона навигации local row = {} -- разбираемая строка шаблона навигации function list () if args[pos+1] == nil then return end row["list_v"]=args[pos+1] row["style_l"]='width:100%;' row["n"]=1 pos=pos+2 end function header ( ) if args[pos+1] == nil then return end row["head_v"]=args[pos+1] row["style_h"]='white-space:nowrap;' pos=pos+2 if args[pos] == "list" then list () row["n"]=2 else if args[pos] == "subh" then subheader ( ) end end end -- { value style colspan } - td -- { head_v style_h list_v style_l n } - tr -- function bilding ( t ) local result="" for i in ipairs (t) do if t[i]["n"]==2 then result=result..'<tr><td style="'..t[i]["style_h"]..'" >'..t[i]["head_v"]..'</td><td>'..t[i]["list_v"]..'</td></tr>' else if t[i]["head_v"] ~= nil then result=result..'<tr><td colspan="2">'..t[i]["head_v"]..'</td></tr>' else result=result..'<tr><td colspan="2">'..t[i]["list_v"]..'</td></tr>' end end end return result end function prepare () row={} while true do if args[pos] == nil then break end if args[pos] == "header" then header() table.insert(t, row ) row={} end if args[pos] == "list" then list() table.insert(t, row ) row={} end end end local p = {} p.nav = function ( frame) args = require('Module:Arguments').getArgs(frame) local style="" if args["стиль"]~= nil then style=style..args["стиль"] end if args["стиль_тела"]~= nil then style=style..args["стиль_тела"] end prepare () return args[1]..'<table class="navbox collapsible nowraplinks" style="margin:auto;'..style..'">'..bilding ( t )..'</table>' end return p