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

Материал из Posmotrelisu
Перейти к навигации Перейти к поиску
Строка 35: Строка 35:
}
}


 
local text=""
local pos=1 -- итерируемая позиция в разбираемом шаблоне
local pos=1 -- итерируемая позиция в разбираемом шаблоне
local result = {} -- массив частей html-кода для последующей склейки
local result = {} -- массив частей html-кода для последующей склейки
Строка 41: Строка 41:


function header ()
function header ()
if args[pos+1] == nil then return end
if args[pos+1] == nil then text=text..'</tr>' return end
local body = "</tr><tr><td>"..args[pos+1].."</td>"
text = "<tr><td>"..args[pos+1].."</td>"
pos=pos+2
pos=pos+2
table.insert (result, body)
if subfun[args[pos]] ~= nil then
subfun[args[pos]]()
end
 
text=text..'</tr>'
 
end
end


function list ()
function list ()
if args[pos+1] == nil then return end
if args[pos+1] == nil then text=text..'</td>' return end
local body = "<td>"..args[pos+1].."</td>"
text=text.."<td>"..args[pos+1].."</td>"
pos=pos+2
pos=pos+2
table.insert (result, body)
end   
end   



Версия 09:54, 12 июля 2024

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

local p = {}; 

p.test = function ( frame )
return "Ad Victoriam!"
end

p.randElem = function ( frame )
local cnt=0

-- Код курильщика
for i, val in ipairs(frame.args) do
 cnt=i
end

local time=os.time()

return time.."  "..cnt.." "..frame.args[time%cnt+1]

end


p.iter_test = function ( frame )
local base=""
for name, val in pairs(frame.args) do
base=base..'<br> key: '..name..' zn: '..val
end
return base

end

local subfun = {
["заголовок"]=header,
["список"]=list

}

local text=""
local pos=1 -- итерируемая позиция в разбираемом шаблоне
local result = {} -- массив частей html-кода для последующей склейки
local args={}

function header ()
if args[pos+1] == nil then text=text..'</tr>' return end
text = "<tr><td>"..args[pos+1].."</td>"
pos=pos+2
	if subfun[args[pos]] ~= nil then
		subfun[args[pos]]()
	end

text=text..'</tr>'

end

function list ()
if args[pos+1] == nil then text=text..'</td>' return end
text=text.."<td>"..args[pos+1].."</td>"
pos=pos+2
end  




return p

--[[
Формат использования

...
|Заголовок|Ими гордится школа
|Список|Вася Петя Маша Вовочка

|Заголовок|Ими гордится город
|Подзаголовок|Пожарные|Список|Горюч Фаер Агни
|Подзаголовок|Врачи|Список|Лечил Оживил
|Подзаголовок|Ученые|Список|Знаток Эксперт Вовочка

|Заголовок|Ими не гордится город
|Заголовок|Вовочка!!!
]]