Moduł:Narzędzia: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) (to się przyda później) |
Ostrzyciel (dyskusja • edycje) M (ech) |
||
(Nie pokazano 16 wersji utworzonych przez 4 użytkowników) | |||
Linia 1: | Linia 1: | ||
local p = {} |
local p = {} |
||
function p. |
function p.firstSmall(frame) |
||
return p._firstSmall(frame.args[1]) |
|||
end |
|||
function p._firstSmall(text) |
|||
if text == nil or text:len() == 0 then |
if text == nil or text:len() == 0 then |
||
return '' |
return '' |
||
Linia 10: | Linia 13: | ||
return text |
return text |
||
end |
|||
function p.firstLarge(frame) |
|||
return p._firstLarge(frame.args[1]) |
|||
end |
|||
function p._firstLarge(text) |
|||
if text == nil or text:len() == 0 then |
|||
return '' |
|||
end |
|||
text = string.sub(text, 1, 1):upper() .. string.sub(text, 2, -1) |
|||
return text |
|||
end |
|||
-- fancy table.concat, zbiera listę do jednego ciągu znaków z przecinkami i "i" między elementami |
|||
function p.concatListPl(list) |
|||
local text = '' |
|||
if #list == 1 then |
|||
text = list[1] |
|||
elseif #list == 2 then |
|||
text = table.concat(list, ' i ') |
|||
elseif #list > 2 then |
|||
text = table.concat(list, ', ', 1, #list - 2) .. ', ' .. |
|||
table.concat(list, ' i ', #list - 1) |
|||
end |
|||
return text |
|||
end |
|||
--[[ zwraca znormalizowaną tablicę argumentów, zarówno dla modułu, jak i nadrzednęgo frame'a |
|||
uwaga: argumenty o indeksach numerycznych będą miały po sprocessowaniu indeksy stringowe (czyli do {{{1}}} |
|||
nie odwołasz się przez tablica[1], tylko tablica["1"]) |
|||
--]] |
|||
function p.getArgs(frame) |
|||
args = {} |
|||
if frame:getParent() ~= nil then |
|||
for name, value in pairs( frame:getParent().args ) do |
|||
if value ~= '' then |
|||
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_') |
|||
args[name1] = value |
|||
end |
|||
end |
|||
end |
|||
for name, value in pairs( frame.args ) do |
|||
if value ~= '' then |
|||
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_') |
|||
args[name1] = value |
|||
end |
|||
end |
|||
return args |
|||
end |
|||
-- escapePattern: eskejpuje stringa do użytku w patternach Lua |
|||
do |
|||
local matches = |
|||
{ |
|||
["^"] = "%^"; |
|||
["$"] = "%$"; |
|||
["("] = "%("; |
|||
[")"] = "%)"; |
|||
["%"] = "%%"; |
|||
["."] = "%."; |
|||
["["] = "%["; |
|||
["]"] = "%]"; |
|||
["*"] = "%*"; |
|||
["+"] = "%+"; |
|||
["-"] = "%-"; |
|||
["?"] = "%?"; |
|||
} |
|||
p.escapePattern = function(s) |
|||
return mw.ustring.gsub(s, ".", matches) |
|||
end |
|||
end |
end |
||
Aktualna wersja na dzień 14:58, 1 kwi 2022
local p = {}
function p.firstSmall(frame)
return p._firstSmall(frame.args[1])
end
function p._firstSmall(text)
if text == nil or text:len() == 0 then
return ''
end
text = string.sub(text, 1, 1):lower() .. string.sub(text, 2, -1)
return text
end
function p.firstLarge(frame)
return p._firstLarge(frame.args[1])
end
function p._firstLarge(text)
if text == nil or text:len() == 0 then
return ''
end
text = string.sub(text, 1, 1):upper() .. string.sub(text, 2, -1)
return text
end
-- fancy table.concat, zbiera listę do jednego ciągu znaków z przecinkami i "i" między elementami
function p.concatListPl(list)
local text = ''
if #list == 1 then
text = list[1]
elseif #list == 2 then
text = table.concat(list, ' i ')
elseif #list > 2 then
text = table.concat(list, ', ', 1, #list - 2) .. ', ' ..
table.concat(list, ' i ', #list - 1)
end
return text
end
--[[ zwraca znormalizowaną tablicę argumentów, zarówno dla modułu, jak i nadrzednęgo frame'a
uwaga: argumenty o indeksach numerycznych będą miały po sprocessowaniu indeksy stringowe (czyli do {{{1}}}
nie odwołasz się przez tablica[1], tylko tablica["1"])
--]]
function p.getArgs(frame)
args = {}
if frame:getParent() ~= nil then
for name, value in pairs( frame:getParent().args ) do
if value ~= '' then
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_')
args[name1] = value
end
end
end
for name, value in pairs( frame.args ) do
if value ~= '' then
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_')
args[name1] = value
end
end
return args
end
-- escapePattern: eskejpuje stringa do użytku w patternach Lua
do
local matches =
{
["^"] = "%^";
["$"] = "%$";
["("] = "%(";
[")"] = "%)";
["%"] = "%%";
["."] = "%.";
["["] = "%[";
["]"] = "%]";
["*"] = "%*";
["+"] = "%+";
["-"] = "%-";
["?"] = "%?";
}
p.escapePattern = function(s)
return mw.ustring.gsub(s, ".", matches)
end
end
return p