Moduł:Narzędzia: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M (e, to nie to)
M (ech)
 
(Nie pokazano 5 wersji utworzonych przez 2 użytkowników)
Linia 29: Linia 29:
end
end


-- fancy table.concat, zbiera listę do jednego ciągu znaków z przecinkami i "i" między elementami
-- zwraca znormalizowaną tablicę argumentów, zarówno dla modułu, jak i nadrzednęgo frame'a
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)
function p.getArgs(frame)
args = {}
args = {}
for name, value in pairs( frame:getParent().args ) do
if frame:getParent() ~= nil then
for name, value in pairs( frame:getParent().args ) do
if value ~= '' then
if value ~= '' then
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_')
local name1 = string.gsub( string.lower( mw.text.trim(name) ), ' ', '_')
args[name1] = value
args[name1] = value
end
end
end
end
end
Linia 48: Linia 67:
end
end


-- escapePattern: eskejpuje stringa do użytku w patternach Lua
-- zwraca kod HTML takiego wykrzyczniczka z ostrzeżeniem po najechaniu myszką
do
function p.makeWarning(value)
local matches =
return '&nbsp;<span class="smw-highlighter" data-title="Ostrzeżenie" data-content="'
{
.. value .. '"><span class="smwtticon warning"></span></span>'
["^"] = "%^";
["$"] = "%$";
["("] = "%(";
[")"] = "%)";
["%"] = "%%";
["."] = "%.";
["["] = "%[";
["]"] = "%]";
["*"] = "%*";
["+"] = "%+";
["-"] = "%-";
["?"] = "%?";
}

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