Moduł:Drzewa link: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M |
Ostrzyciel (dyskusja • edycje) M (wszem) |
||
(Nie pokazano 32 wersji utworzonych przez 2 użytkowników) | |||
Linia 2: | Linia 2: | ||
local tools = require('Moduł:Narzędzia') |
local tools = require('Moduł:Narzędzia') |
||
⚫ | |||
-- żywcem zerżnięte z https://gist.github.com/jaredallard/ddb152179831dd23b230 |
|||
['(główna)'] = 'artykułów', |
|||
function string:split(delimiter) |
|||
['grafiki'] = 'grafik', |
|||
⚫ | |||
['nonnews'] = 'NonNewsów', |
|||
⚫ | |||
['słownik'] = 'haseł słownikowych', |
|||
local delim_from, delim_to = string.find(self, delimiter, from) |
|||
['cytaty'] = 'cytatów', |
|||
while delim_from do |
|||
['poradniki'] = 'poradników', |
|||
table.insert(result, string.sub(self, from, delim_from - 1)) |
|||
⚫ | |||
from = delim_to + 1 |
|||
} |
|||
delim_from, delim_to = string.find(self, delimiter, from) |
|||
⚫ | |||
table.insert(result, string.sub(self, from)) |
|||
⚫ | |||
end |
|||
function p. |
function p._linkCats(args) |
||
local |
local links = {} |
||
{['główna']='główna', ['grafiki']='grafiki', ['nonnews']='nonnews', |
|||
⚫ | |||
['słownik']='słownik', ['cytaty']='cytaty', ['poradniki']='poradniki', |
|||
cat = mw.text.trim(cat or '') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
local prefix = mw.ustring.lower(mw.ustring.match(cat, "(.+) – ") or '(główna)') |
|||
local cat |
|||
local treeName = prefixMap[prefix] or 'artykułów' |
|||
local namespace |
|||
table.insert(links, '<b>[[:Kategoria:' .. cat .. '|' .. treeName .. ']]</b>') |
|||
⚫ | |||
if args[space] ~= nil then |
|||
cat = args[space] |
|||
namespace = space |
|||
end |
end |
||
end |
end |
||
if cat ~= nil and namespace ~= nil then |
|||
⚫ | |||
return namespace .. ', ' .. '[[:Kategoria:' .. cat .. ']]\n' |
|||
if #links == 0 then |
|||
⚫ | |||
text = 'Błąd – nie podano żadnych linków do innych kategorii.' |
|||
if args['1'] == nil then return 'arg1 nil' |
|||
elseif #links == 1 then |
|||
else |
|||
text = 'Ta kategoria ma swój odpowiednik w drzewie kategorii ' .. links[1] .. '.' |
|||
cat = args['1'] |
|||
⚫ | |||
⚫ | |||
text = 'Ta kategoria ma swoje odpowiedniki w drzewach kategorii ' .. tools.concatListPl(links) .. '.' |
|||
local namespace = namespaces[string:split(cat, " – ")[0].lower()] |
|||
else |
|||
local namespace = 'główna' end |
|||
return namespace .. ', ' .. '[[:Kategoria:' .. cat .. ']]\n' end |
|||
end |
end |
||
⚫ | |||
title = 'Ambox', |
|||
args = { |
|||
grafika = '[[Plik:Dwa drzewa kategorii.svg|x40px]]', |
|||
tekst = text |
|||
} |
|||
} |
|||
end |
end |
||
function p.linkCats(frame) |
|||
⚫ | |||
return frame:expandTemplate(p._linkCats(args)) |
|||
⚫ | |||
return p |
return p |
Aktualna wersja na dzień 14:58, 1 kwi 2022
local p = {}
local tools = require('Moduł:Narzędzia')
local prefixMap = {
['(główna)'] = 'artykułów',
['grafiki'] = 'grafik',
['nonnews'] = 'NonNewsów',
['słownik'] = 'haseł słownikowych',
['cytaty'] = 'cytatów',
['poradniki'] = 'poradników',
['nonźródła'] = 'nonźródeł'
}
function p._linkCats(args)
local links = {}
for _, cat in pairs(args) do
cat = mw.text.trim(cat or '')
if cat ~= '' then
local prefix = mw.ustring.lower(mw.ustring.match(cat, "(.+) – ") or '(główna)')
local treeName = prefixMap[prefix] or 'artykułów'
table.insert(links, '<b>[[:Kategoria:' .. cat .. '|' .. treeName .. ']]</b>')
end
end
local text = ''
if #links == 0 then
text = 'Błąd – nie podano żadnych linków do innych kategorii.'
elseif #links == 1 then
text = 'Ta kategoria ma swój odpowiednik w drzewie kategorii ' .. links[1] .. '.'
else
text = 'Ta kategoria ma swoje odpowiedniki w drzewach kategorii ' .. tools.concatListPl(links) .. '.'
end
return {
title = 'Ambox',
args = {
grafika = '[[Plik:Dwa drzewa kategorii.svg|x40px]]',
tekst = text
}
}
end
function p.linkCats(frame)
local args = tools.getArgs(frame)
return frame:expandTemplate(p._linkCats(args))
end
return p