Modul:SK: razlika između inačica

Izvor: Hrvatska internetska enciklopedija
Prijeđi na navigaciju Prijeđi na pretraživanje
mNema sažetka uređivanja
mNema sažetka uređivanja
 
Nisu prikazane 2 međuinačice
Redak 1: Redak 1:
--------------------------------------------------------------------
local p = {}
--  SK PRO — Optimizirani Modul:SK za enciklopedija.cc
--  Verzija: 1.0
--  Autor: Copilot + kingfisher01
--  Stabilan, brz, bez hrwiki ovisnosti
--------------------------------------------------------------------


local p = {}
p.db = {}


--------------------------------------------------------------------
--------------------------------------------------------------------
-- 1) Tematske boje enciklopedija.cc (profesionalna paleta)
-- 1) Učitavanje data modula
--------------------------------------------------------------------
--------------------------------------------------------------------


p.colors = {
local modules = {
     primary  = "#003366",
     "Modul:SK/Data1",
     secondary = "#336699",
     "Modul:SK/Data2",
     accent    = "#6699cc",
     "Modul:SK/Data3",
     light     = "#eef5ff",
     "Modul:SK/Data4",
     dark      = "#001a33",
     "Modul:SK/Data5",
     border    = "#aaccee",
     "Modul:SK/Data6",
     "Modul:SK/Data7",
}
}


--------------------------------------------------------------------
for _, name in ipairs(modules) do
-- 2) Profesionalni infookvir (bez ovisnosti)
     local ok, raw = pcall(require, name)
--------------------------------------------------------------------
     if ok and type(raw) == "string" then
 
        for line in raw:gmatch("[^\n]+") do
function p.infobox(frame)
     local args = frame:getParent().args
     local title = args["naslov"] or args["title"] or "Infookvir"


    local out = {}
            -- NOVI FORMAT: 6 polja
    table.insert(out, '{| class="infobox" style="width:260px; border:1px solid ' .. p.colors.border .. '; background:' .. p.colors.light .. ';"')
            local code, naziv, pop, area, year, density =
    table.insert(out, '|-')
                line:match("([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)")
    table.insert(out, string.format('| style="background:%s; color:white; text-align:center; font-size:120%%; padding:6px;" | %s',
        p.colors.primary, title))


    for k, v in pairs(args) do
            if code then
        if k ~= "naslov" and k ~= "title" and v ~= "" then
                p.db[code] = {
            table.insert(out, '|-')
                    naziv = naziv,
            table.insert(out, string.format('| style="font-weight:bold; width:35%%;" | %s || %s', k, v))
                    pop = tonumber(pop),
                    area = tonumber(area),
                    year = tonumber(year),
                    density = density, -- ostaje string jer koristiš decimalni zarez
                }
            end
         end
         end
     end
     end
    table.insert(out, '|}')
    return table.concat(out, "\n")
end
end


--------------------------------------------------------------------
--------------------------------------------------------------------
-- 3) Profesionalni navbox (bez ovisnosti)
-- 2) Format funkcije
--------------------------------------------------------------------
--------------------------------------------------------------------


function p.navbox(frame)
function p.format(code, mode)
     local args = frame:getParent().args
     local d = p.db[code]
     local title = args["naslov"] or "Navigacija"
     if not d then return "" end


     local out = {}
     if mode == "p" then return d.naziv end
     table.insert(out, '{| class="navbox" style="width:100%; border:1px solid ' .. p.colors.border .. '; background:' .. p.colors.light .. ';"')
     if mode == "a" then return d.pop end
     table.insert(out, '|-')
    if mode == "d" then return d.area end
     table.insert(out, string.format('| style="background:%s; color:white; text-align:center; font-size:110%%; padding:4px;" | %s',
     if mode == "g" then return d.year end
        p.colors.primary, title))
     if mode == "y" then return d.density end


    for k, v in pairs(args) do
     return ""
        if k ~= "naslov" and v ~= "" then
            table.insert(out, '|-')
            table.insert(out, string.format('| style="padding:4px;" | %s', v))
        end
    end
 
    table.insert(out, '|}')
     return table.concat(out, "\n")
end
end


--------------------------------------------------------------------
--------------------------------------------------------------------
-- 4) Profesionalni “badge” stilovi (opcionalno)
-- 3) Glavna funkcija
--------------------------------------------------------------------
--------------------------------------------------------------------


function p.badge(frame)
function p.sk(frame)
     local args = frame:getParent().args
     local args = frame.args
     local text = args[1] or "Oznaka"
     local mode = args[1]
     local color = args["boja"] or p.colors.primary
     local code = args[2]
 
    if not mode or not code then return "" end
     return string.format('<span style="background:%s; color:white; padding:2px 6px; border-radius:4px; font-size:90%%;">%s</span>',
     return p.format(code, mode)
        color, text)
end
end
--------------------------------------------------------------------
-- 5) Sigurnosni fallback (sprječava sve greške)
--------------------------------------------------------------------
setmetatable(p, {
    __index = function()
        return function() return "" end
    end
})


return p
return p

Posljednja izmjena od 26. ožujak 2026. u 09:56

Dokumentacija modula
== About ==

Get statistic data about Slovak municipalities.

This template is a sibling of Predložak:SK.

This template use the data from CC-BY database.

Original first author: meta.wikimedia.org/wiki/User:Dušan Kreheľ

Reference implementation is on hrwiki.

Parameters

First paramer

Meaning Parameter Code Code output
Population p {{#invoke:SK|sk|p|SK0417524395}}
Population
(source URL)
P {{#invoke:SK|sk|P|SK0417524395}}<br>{{#invoke:SK|sk|P|SK}}<br>{{#invoke:SK|sk|P|SK0106}}

Population
(ex. for table)
p {{#invoke:SK|sk|o|SK0417524395}}
Population Id r {{#invoke:SK|sk|r|SK0417524395}}
Area a {{#invoke:SK|sk|a|SK0417524395}}
Area
(source URL)
A {{#invoke:SK|sk|A|SK0417524395}}
Area Id b {{#invoke:SK|sk|b|SK0417524395}}
Population density
(as population/area)
d {{#invoke:SK|sk|d}}
Data year y {{#invoke:SK|sk|y}}
Last acces l {{#invoke:SK|sk|l}}
Last update u {{#invoke:SK|sk|u}}
Is slovak municipality
(none support %i)
i {{#invoke:SK|sk|i|SK0417524395}}
Get NUTS/LAU code
(none support %e)
e

You can used both the format string like printf() with parameters from table.

Code: {{#invoke:SK|sk|%p (source: %P)|SK0417524395}}
Output:

Second parameter

It is a STUN or LAU code for place sup-place (ex. SK0417524395). If none, then code is automatic based on the actual page.


local p = {}

p.db = {}

--------------------------------------------------------------------
-- 1) Učitavanje data modula
--------------------------------------------------------------------

local modules = {
    "Modul:SK/Data1",
    "Modul:SK/Data2",
    "Modul:SK/Data3",
    "Modul:SK/Data4",
    "Modul:SK/Data5",
    "Modul:SK/Data6",
    "Modul:SK/Data7",
}

for _, name in ipairs(modules) do
    local ok, raw = pcall(require, name)
    if ok and type(raw) == "string" then
        for line in raw:gmatch("[^\n]+") do

            -- NOVI FORMAT: 6 polja
            local code, naziv, pop, area, year, density =
                line:match("([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)")

            if code then
                p.db[code] = {
                    naziv = naziv,
                    pop = tonumber(pop),
                    area = tonumber(area),
                    year = tonumber(year),
                    density = density, -- ostaje string jer koristiš decimalni zarez
                }
            end
        end
    end
end

--------------------------------------------------------------------
-- 2) Format funkcije
--------------------------------------------------------------------

function p.format(code, mode)
    local d = p.db[code]
    if not d then return "" end

    if mode == "p" then return d.naziv end
    if mode == "a" then return d.pop end
    if mode == "d" then return d.area end
    if mode == "g" then return d.year end
    if mode == "y" then return d.density end

    return ""
end

--------------------------------------------------------------------
-- 3) Glavna funkcija
--------------------------------------------------------------------

function p.sk(frame)
    local args = frame.args
    local mode = args[1]
    local code = args[2]
    if not mode or not code then return "" end
    return p.format(code, mode)
end

return p