Moduł:Drzewa link: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M |
Ostrzyciel (dyskusja • edycje) M (cyk) |
||
Linia 2: | Linia 2: | ||
local tools = require('Moduł:Narzędzia') |
local tools = require('Moduł:Narzędzia') |
||
⚫ | |||
⚫ | |||
['grafiki'] = 'grafik', |
|||
⚫ | |||
['słownik'] = 'haseł słownikowych', |
|||
⚫ | |||
['poradniki'] = 'poradników', |
|||
⚫ | |||
} |
|||
function p._linkCats( |
function p._linkCats(args) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local use_plural = false else local use_plural = true end |
|||
if use_plural then |
|||
treessuf = 'ie' else treessuf = 'ach' end |
|||
⚫ | |||
for i=1, #namespaces do |
|||
local namespace = namespaces[i] |
|||
local category = categories[i] |
|||
local link = comms[namespace] .. ': \'\'\'' .. |
|||
'[[:Kategoria:' .. category .. ']]' .. '\'\'\'' |
|||
table.insert(catlinks, link) end |
|||
⚫ | |||
return {title='Ambox', args={ |
|||
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 |
|||
⚫ | |||
local treeSuffix = 'ach' |
|||
if #links == 0 then |
|||
text = 'Błąd – nie podano żadnych linków do innych kategorii.' |
|||
elseif #links == 1 then |
|||
treeSuffix = 'ie' |
|||
text = links[1] |
|||
elseif #links == 2 then |
|||
text = table.concat(links, ' i ') |
|||
else |
|||
text = table.concat(links, ', ', 1, #links - 2) .. ', ' .. |
|||
table.concat(links, ' i ', #links - 1) |
|||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
return { |
|||
title = 'Ambox', |
|||
args = { |
|||
⚫ | |||
tekst = text |
|||
} |
|||
} |
|||
end |
end |
||
function p.linkCats(frame) |
function p.linkCats(frame) |
||
⚫ | |||
{['główna']='główna', ['grafiki']='grafiki', ['nonnews']='nonnews', |
|||
['słownik']='słownik', ['cytaty']='cytaty', ['poradniki']='poradniki', |
|||
['nonźródła']='nonźródła'} |
|||
local args = tools.getArgs(frame) |
local args = tools.getArgs(frame) |
||
⚫ | |||
local _namespaces = {} |
|||
⚫ | |||
⚫ | |||
if cat == nil then return 'cat - nil' end |
|||
namespace = namespaces_[cat:match("(.+) – "):lower()] or 'główna' |
|||
table.insert(_namespaces, namespace) |
|||
table.insert(_cats, cat) |
|||
⚫ | |||
return table.concat(_namespaces, ', ') .. table.concat(_cats, ', ') |
|||
⚫ | |||
end |
end |
||
Wersja z 10:26, 3 gru 2020
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 = ''
local treeSuffix = 'ach'
if #links == 0 then
text = 'Błąd – nie podano żadnych linków do innych kategorii.'
elseif #links == 1 then
treeSuffix = 'ie'
text = links[1]
elseif #links == 2 then
text = table.concat(links, ' i ')
else
text = table.concat(links, ', ', 1, #links - 2) .. ', ' ..
table.concat(links, ' i ', #links - 1)
end
if #links > 0 then
text = 'Ta kategoria ma swój odpowiednik w drzew' .. treeSuffix
.. ' kategorii ' .. text .. '.'
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