Modul:Tools: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
local function strtok ( stringStr, delimiterStr )
-- internal Functions
local s = stringStr..delimiterStr
local words = {}
for w in (s):gmatch('([^'..delimiterStr..']*)'..delimiterStr) do
    table.insert(words, w)
end
return words
end
 
local function rmNamespace ( pageName )
return strtok(pageName,':')[2] or pageName
end
 
local function _getParameters( frame_args, arg_list )
local function _getParameters( frame_args, arg_list )
     local new_args = {};
     local new_args = {};
Zeile 31: Zeile 19:
local tools = {}
local tools = {}


-- Funktions to be used in other modules
function tools.strtok ( stringStr, delimiterStr )
local s = stringStr..delimiterStr
local words = {}
for w in (s):gmatch('([^'..delimiterStr..']*)'..delimiterStr) do
    table.insert(words, w)
end
return words
end
function tools.rmNamespace ( pageName )
return tools.strtok(pageName,':')[2] or pageName
end
-- Funktions to be used in templates
function tools.firstBasepagename (frame)
function tools.firstBasepagename (frame)


     local new_args = _getParameters( frame.args, {'page'} );
     local new_args = _getParameters( frame.args, {'page'} );
     local page = new_args['page'] or '';
     local page = new_args['page'] or '';
     return strtok(rmNamespace(page),'/')[1] or page
     return tools.strtok(tools.rmNamespace(page),'/')[1] or page
end
end


return tools
return tools

Version vom 19. Mai 2017, 09:33 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Tools/doc erstellt werden

-- internal Functions
local function _getParameters( frame_args, arg_list )
    local new_args = {};
    local index = 1;
    local value;
    
    for i,arg in ipairs( arg_list ) do
        value = frame_args[arg]
        if value == nil then
            value = frame_args[index];
            index = index + 1;
        end
        new_args[arg] = value;
    end
    
    return new_args;
end 

local tools = {}

-- Funktions to be used in other modules
function tools.strtok ( stringStr, delimiterStr )
	local s = stringStr..delimiterStr
	local words = {}
	for w in (s):gmatch('([^'..delimiterStr..']*)'..delimiterStr) do 
	    table.insert(words, w) 
	end
	return words
end

function tools.rmNamespace ( pageName )
	return tools.strtok(pageName,':')[2] or pageName
end

-- Funktions to be used in templates
function tools.firstBasepagename (frame)

    local new_args = _getParameters( frame.args, {'page'} );
    local page = new_args['page'] or '';
    return tools.strtok(tools.rmNamespace(page),'/')[1] or page
end

return tools