Modul:CSVParser
Megjelenés
A modult a Modul:CSVParser/doc lapon tudod dokumentálni
local p = {}
function p.megjelenit(frame)
-- Paraméterek átvétele a sablonból
local args = frame.args[1] and frame.args or frame:getParent().args
-- 1. paraméter: Szűrő (pl. Cactaceae)
local szuro = args[1]
if szuro then
szuro = szuro:gsub("^%s*(.-)%s*$", "%1"):lower()
if szuro == "" then szuro = nil end
end
-- 2. paraméter: Oldalankénti sorok száma (alapértelmezett: 50)
local sor_limit = tonumber(args[2]) or 50
local status, adatModul = pcall(require, 'Modul:SzukkulensTaxonok')
if not status then
return "Hiba: A 'Modul:SzukkulensTaxonok' nem található!"
end
local adatok = adatModul.getAdatok()
if not adatok or #adatok == 0 then
return "Hiba: Az adatok üresek!"
end
-- A 'data-page-length' attribútum állítja be az alapértelmezett oldalhosszt
local res = '{| class="wikitable sortable datatable-hook" data-page-length="' .. sor_limit .. '" style="width:100%; font-size:90%;"\n'
local megjelenitett_sorok_szama = 0
for i, sor in ipairs(adatok) do
local megfelel = false
if i == 1 then
megfelel = true
elseif not szuro then
megfelel = true
else
for _, cella in ipairs(sor) do
if cella:lower():find(szuro, 1, true) then
megfelel = true
break
end
end
end
if megfelel then
res = res .. "|-\n"
local jel = (i == 1) and "!" or "|"
if i == 1 then
res = res .. "! #\n"
else
megjelenitett_sorok_szama = megjelenitett_sorok_szama + 1
res = res .. "| " .. megjelenitett_sorok_szama .. "\n"
end
local oszlop_terv = {
{lat = 1, hun = 2}, {lat = 3, hun = 4}, {lat = 5, hun = 6},
{lat = 7, hun = nil}, {lat = 8, hun = nil}, {lat = 9, hun = 10}
}
for _, mapping in ipairs(oszlop_terv) do
local latin = sor[mapping.lat] or ""
local magyar = mapping.hun and sor[mapping.hun] or ""
latin = latin:gsub("^%s*(.-)%s*$", "%1")
magyar = magyar:gsub("^%s*(.-)%s*$", "%1")
local cella_ertek = ""
if i == 1 then
cella_ertek = latin
else
if latin == "" or latin == " " then
cella_ertek = " "
else
local link_szoveg = latin
if mapping.lat == 9 then link_szoveg = "''" .. latin .. "''" end
local link = "[[:Kategória:" .. latin .. "|" .. link_szoveg .. "]]"
if magyar ~= "" and magyar ~= " " then
cella_ertek = link .. " (" .. magyar .. ")"
else
cella_ertek = link
end
end
end
res = res .. jel .. " " .. cella_ertek .. "\n"
end
end
end
res = res .. "|}"
return res
end
return p