Modul:SK: razlika između inačica
Prijeđi na navigaciju
Prijeđi na pretraživanje
mNema sažetka uređivanja |
mNema sažetka uređivanja |
||
| Redak 57: | Redak 57: | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
-- 3) Glavna funkcija | -- 3) Glavna funkcija (POPRAVLJENA) | ||
-------------------------------------------------------------------- | -------------------------------------------------------------------- | ||
function p.sk(frame) | function p.sk(frame) | ||
-- Prvo gledamo parametre iz #invoke poziva | |||
local args = frame.args | local args = frame.args | ||
local mode = args[1] | local mode = args[1] | ||
local code = args[2] | local code = args[2] | ||
-- Ako code nije poslan izravno u #invoke, tražimo ga u predlošku ({{{1}}}) | |||
if not code or code == "" or code == "{{{1}}}" then | |||
local parentArgs = frame:getParent().args | |||
code = parentArgs[1] | |||
end | |||
-- Ako i dalje nemamo mode ili code, vraćamo prazno | |||
if not mode or not code then return "" end | if not mode or not code then return "" end | ||
-- Čišćenje razmaka (trim) | |||
code = code:match("^%s*(.-)%s*$") | |||
return p.format(code, mode) | return p.format(code, mode) | ||
end | end | ||
Inačica od 26. ožujak 2026. u 12:51
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|SK518581}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Population (source URL) |
P | {{#invoke:SK|sk|P|SK0417524395}}<br>{{#invoke:SK|sk|P|SK}}<br>{{#invoke:SK|sk|P|SK0106}} | Script error: The module returned a nil value. It is supposed to return an export table. Script error: The module returned a nil value. It is supposed to return an export table. Script error: The module returned a nil value. It is supposed to return an export table. |
| Population (ex. for table) |
p | {{#invoke:SK|sk|o|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Population Id | r | {{#invoke:SK|sk|r|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Area | a | {{#invoke:SK|sk|a|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Area (source URL) |
A | {{#invoke:SK|sk|A|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Area Id | b | {{#invoke:SK|sk|b|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Population density (as population/area) |
d | {{#invoke:SK|sk|d}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Data year | y | {{#invoke:SK|sk|y}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Last acces | l | {{#invoke:SK|sk|l}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Last update | u | {{#invoke:SK|sk|u}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| Is slovak municipality (none support %i) |
i | {{#invoke:SK|sk|i|SK0417524395}} | Script error: The module returned a nil value. It is supposed to return an export table. |
| 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: | Script error: The module returned a nil value. It is supposed to return an export table. |
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 (POPRAVLJENA)
--------------------------------------------------------------------
function p.sk(frame)
-- Prvo gledamo parametre iz #invoke poziva
local args = frame.args
local mode = args[1]
local code = args[2]
-- Ako code nije poslan izravno u #invoke, tražimo ga u predlošku ({{{1}}})
if not code or code == "" or code == "{{{1}}}" then
local parentArgs = frame:getParent().args
code = parentArgs[1]
end
-- Ako i dalje nemamo mode ili code, vraćamo prazno
if not mode or not code then return "" end
-- Čišćenje razmaka (trim)
code = code:match("^%s*(.-)%s*$")
return p.format(code, mode)
end