Ugrás a tartalomhoz

„Modul:CSVParser” változatai közötti eltérés

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
 
(9 közbenső módosítás ugyanattól a felhasználótól nincs mutatva)
2. sor: 2. sor:


function p.megjelenit(frame)
function p.megjelenit(frame)
     -- Beolvassuk az adatokat a másik modulból
     -- Paraméterek átvétele a sablonból
     local success, adatok = pcall(function() return require('Modul:Adatok').getAdatok() end)
     local args = frame.args[1] and frame.args or frame:getParent().args
      
      
     if not success or #adatok == 0 then  
    -- 1. paraméter: Szűrő (pl. Cactaceae)
         return "Hiba: Az adatok nem tölthetők be vagy üresek!"  
    local szuro = args[1]
     if szuro then
         szuro = szuro:gsub("^%s*(.-)%s*$", "%1"):lower()
        if szuro == "" then szuro = nil end
     end
     end


     local res = '{| class="wikitable sortable datatable" style="width:100%; font-size:90%;"\n'
    -- 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'
-- A 'datatable-hook' mellé bekerült a stripe, hover és compact osztály
     local res = '{| class="wikitable sortable datatable-hook stripe hover compact" data-page-length="' .. sor_limit .. '" style="width:100%; font-size:90%;"\n'  
    local megjelenitett_sorok_szama = 0
      
      
     for i, sor in ipairs(adatok) do
     for i, sor in ipairs(adatok) do
         res = res .. "|-\n"
         local megfelel = false
        -- Első sor legyen fejléc (!)
        if i == 1 then
        local elvalaszto = (i == 1) and "!" or "|"
            megfelel = true
       
        elseif not szuro then
        for _, tartalom in ipairs(sor) do
            megfelel = true
            -- Ha a cella üres, teszünk bele egy szóközt, hogy ne essen szét a keret
        else
            local szoveg = (tartalom == "") and " " or tartalom
            for _, cella in ipairs(sor) do
            res = res .. elvalaszto .. " " .. szoveg .. "\n"
                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
     end
     end

A lap jelenlegi, 2026. január 4., 20:23-kori változata

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'
	-- A 'datatable-hook' mellé bekerült a stripe, hover és compact osztály
    local res = '{| class="wikitable sortable datatable-hook stripe hover compact" 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