Modul:Tools: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
K (22 Versionen von wikivoyage:Modul:Tools importiert) |
||
(17 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
-- internal Functions | |||
local function _getParameters( frame_args, arg_list ) | |||
local | |||
function | |||
local new_args = {}; | local new_args = {}; | ||
local index = 1; | local index = 1; | ||
Zeile 25: | Zeile 17: | ||
end | end | ||
local tools = {} | |||
-- Functions 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 | |||
function tools.rmBRTag ( text ) | |||
return mw.ustring.gsub( text, '<br */*>', ' ' ) | |||
end | |||
-- Functions to be used in templates | |||
function tools.firstBasepagename (frame) | function tools.firstBasepagename (frame) | ||
local new_args = | local new_args = _getParameters( frame.args, {'page'} ); | ||
local page = new_args['page'] or ''; | local page = new_args['page'] or ''; | ||
return | return tools.strtok(tools.rmNamespace(page),'/')[1] or page | ||
end | end | ||
return tools | return tools |
Aktuelle Version vom 27. Januar 2023, 07:40 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 = {} -- Functions 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 function tools.rmBRTag ( text ) return mw.ustring.gsub( text, '<br */*>', ' ' ) end -- Functions 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