Modul:InfoboxCore

Izvor: Hrvatska internetska enciklopedija
Inačica 787382 od 1. srpanj 2026. u 11:38 koju je unio WikiSysop (razgovor | doprinosi) (Stvorena nova stranica sa sadržajem: »local p = {} local util = {} local row = {} local section = {} local image = {} local dates = {} local normdata = {} function util.isEmpty(v) return v == nil or v == '' or mw.text.trim(v) == '' end function util.showIf(label, value) if util.isEmpty(value) then return '' end return row.render(label, value) end function row.render(label, value) return string.format( '<tr><th>%s</th><td>%s</td></tr>', la...«.)
(razl) ←Starija inačica | vidi trenutačnu inačicu (razl) | Novija inačica→ (razl)
Prijeđi na navigaciju Prijeđi na pretraživanje
Dokumentacija modula


local p = {}

local util = {}
local row = {}
local section = {}
local image = {}
local dates = {}
local normdata = {}

function util.isEmpty(v)
    return v == nil or v == '' or mw.text.trim(v) == ''
end

function util.showIf(label, value)
    if util.isEmpty(value) then
        return ''
    end
    return row.render(label, value)
end

function row.render(label, value)
    return string.format(
        '<tr><th>%s</th><td>%s</td></tr>',
        label,
        value
    )
end

function p.renderHeader(args)
    local name = args.ime or args.name or mw.title.getCurrentTitle().text
    return string.format(
        '<tr class="infobox-header"><th colspan="2">%s</th></tr>',
        name
    )
end

function image.render(args)
    if util.isEmpty(args.slika) then
        return ''
    end
    local caption = args.opis_slike or ''
    return string.format(
        '<tr><td colspan="2" class="infobox-image">%s<div class="infobox-caption">%s</div></td></tr>',
        args.slika,
        caption
    )
end

function dates.format(date)
    if util.isEmpty(date) then
        return ''
    end
    return mw.getContentLanguage():formatDate('j. F Y', date)
end

function section.render(args, mode)
    local out = {}

    table.insert(out, util.showIf('Rođenje', dates.format(args.rodjenje)))
    table.insert(out, util.showIf('Mjesto rođenja', args.mjesto_rodjenja))

    table.insert(out, util.showIf('Smrt', dates.format(args.smrt)))
    table.insert(out, util.showIf('Mjesto smrti', args.mjesto_smrti))

    table.insert(out, util.showIf('Zanimanje', args.zanimanje))
    table.insert(out, util.showIf('Nacionalnost', args.nacionalnost))

    return table.concat(out, "\n")
end

function normdata.render(args)
    local out = {}

    if not util.isEmpty(args.viaf) then
        table.insert(out, '[https://viaf.org/viaf/' .. args.viaf .. ' VIAF]')
    end

    if not util.isEmpty(args.eb) then
        table.insert(out, '[https://enciklopedija.cc/EB/' .. args.eb .. ' EB]')
    end

    if #out == 0 then
        return ''
    end

    return '<tr><th>Normativni nadzor</th><td>' .. table.concat(out, ' · ') .. '</td></tr>'
end

function p.render(args, mode)
    local output = {}

    table.insert(output, p.renderHeader(args))
    table.insert(output, image.render(args))
    table.insert(output, section.render(args, mode))
    table.insert(output, normdata.render(args))

    return table.concat(output, "\n")
end

function p.biography(frame)
    local args = frame:getParent().args
    return p.render(args, "biography")
end

return p