Модуль:Навигация: различия между версиями

Материал из Posmotrelisu
Перейти к навигации Перейти к поиску
Строка 1: Строка 1:
local text=""
local text=""
local pos=1 -- итерируемая позиция в разбираемом шаблоне
local pos=1 -- итерируемая позиция в разбираемом шаблоне
local args = require('Module:Arguments').getArgs(frame)
-- local args = require('Module:Arguments').getArgs(frame)
   
  local args = frame.args


function list ( row )
function list ( row )

Версия 00:09, 18 июля 2024

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

local text=""
local pos=1 -- итерируемая позиция в разбираемом шаблоне
-- local args = require('Module:Arguments').getArgs(frame)
 local args = frame.args

function list ( row )
if args[pos+1] == nil then return end
row["list_v"]=args[pos+1]
row["n"]=1
pos=pos+2
end  

function header ( row )
if args[pos+1] == nil then return end
row["head_v"]=args[pos+1]
pos=pos+2
	if args[pos] == "list" then
		list (row)
		row["n"]=2
	else 
		if args[pos] == "subh" then 
		subheader ( row )
		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>'..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 ()
local row={}
local prep={}

while true do
	if args[pos] == nil then return t end
	if args[pos] == "header" then 
	header ( row )
	table.insert(t, row)
	end
	
	if args[pos] == "list" then 
	list ( row )
	table.insert(t, row)
	end
	
end

end

local p = {}
p.nav = function ()
local t= prepare ()
return '<table class="wikitable"'..bilding ( t )..'</table>'


end

return p