Modul:Citation/CS1/Utilities

Izvor: Hrvatska internetska enciklopedija
Inačica 640286 od 12. siječanj 2026. u 10:16 koju je unio WikiSysop (razgovor | doprinosi)
(razl) ←Starija inačica | vidi trenutačnu inačicu (razl) | Novija inačica→ (razl)
Prijeđi na navigaciju Prijeđi na pretraživanje

Script error: The function "nonexistent" does not exist.

-- Modul:Citation/CS1/Utilities
-- Minimalna verzija kompatibilna s hrvatskim CS1 modulom

local p = {}

function p.format_authors(list)
    if #list == 0 then return nil end
    if #list == 1 then return list[1] end
    if #list == 2 then return list[1] .. ' i ' .. list[2] end
    if #list >= 4 then return list[1] .. ' et al.' end

    local last = table.remove(list)
    return table.concat(list, ', ') .. ' i ' .. last
end

function p.citeref_key(authors, year)
    local key = ''

    if type(authors) == 'table' then
        key = table.concat(authors, '')
    elseif type(authors) == 'string' then
        key = authors
    end

    if year then
        key = key .. tostring(year)
    end

    return key
end


-- Trim whitespace
function p.trim(s)
    if not s then return nil end
    return mw.text.trim(s)
end

-- Provjera je li vrijednost postavljena
function p.is_set(v)
    return v ~= nil and mw.text.trim(v) ~= ""
end

-- Formatiranje liste s razmacima
function p.join(parts, sep)
    sep = sep or " "
    local out = {}
    for _, v in ipairs(parts) do
        if p.is_set(v) then
            table.insert(out, v)
        end
    end
    return table.concat(out, sep)
end

-- Jednostavne poruke o greškama
function p.error_message(msg)
    return '<span class="citation-error" style="color:#b00;">' .. msg .. '</span>'
end

return p