کاربر ناشناس
Replace Module:No globals with require( "strict" )
جز (۱ نسخه واردشده) |
(Replace Module:No globals with require( "strict" )) |
||
خط ۱: | خط ۱: | ||
require(' | require('strict'); | ||
local error_msg = '<span style=\"font-size:100%\" class=\"error\"> | local error_msg = '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">|_template=</code> missing or empty</span>'; | ||
خط ۵۹: | خط ۵۹: | ||
for _, alias_pair in ipairs (T) do -- loop through the table of alias pairs | for _, alias_pair in ipairs (T) do -- loop through the table of alias pairs | ||
l_name, t_name = | l_name, t_name = alias_pair:match ('(.-)%s*:%s*(.+)'); -- from each pair, get local and target parameter names | ||
if l_name and t_name then -- if both are set | if l_name and t_name then -- if both are set | ||
if | if tonumber (l_name) then | ||
l_name = | l_name = tonumber (l_name); -- convert number-as-text to a number | ||
end | end | ||
mapped_aliases[l_name] = t_name; -- add them to the map table | mapped_aliases[l_name] = t_name; -- add them to the map table | ||
خط ۱۸۷: | خط ۱۸۷: | ||
if 'string' == type (k) then -- only named parameters can be enumerated | if 'string' == type (k) then -- only named parameters can be enumerated | ||
if alias_map[k..'#'] then -- non-enumerated alias matches enumerated parameter pattern? enumerator at end only | if alias_map[k..'#'] then -- non-enumerated alias matches enumerated parameter pattern? enumerator at end only | ||
pframe_args[ | pframe_args[alias_map[k..'#']:gsub('#', '')] = v; -- remove '#' and copy parameter to pframe_args table | ||
pframe_args[k] = nil; -- unset the alias | pframe_args[k] = nil; -- unset the alias | ||
elseif | elseif k:match ('%d+') then -- if this parameter name contains digits | ||
local temp = | local temp = k:gsub ('%d+', '#'); -- make a copy; digits replaced with single '#' | ||
local enum = | local enum = k:match ('%d+'); -- get the enumerator | ||
if alias_map[temp] then -- if this parameter is a recognized enumerated alias | if alias_map[temp] then -- if this parameter is a recognized enumerated alias | ||
pframe_args[ | pframe_args[alias_map[temp]:gsub('#', enum)] = v; -- use canonical name and replace '#' with enumerator and add to pframe_args | ||
pframe_args[k] = nil; -- unset the alias | pframe_args[k] = nil; -- unset the alias | ||
end | end | ||
خط ۲۴۱: | خط ۲۴۱: | ||
Template entry point. Call this function to 'display' the source for the working template. This function added | Template entry point. Call this function to 'display' the source for the working template. This function added | ||
as a result of a TfD here: | as a result of a TfD here: Wikipedia:Templates_for_discussion/Log/2018_April_28#Module:PassArguments | ||
This function replaces a similarly named function which was used in {{cite compare}} and {{cite compare2}} | This function replaces a similarly named function which was used in {{cite compare}} and {{cite compare2}} | ||
خط ۲۵۸: | خط ۲۵۸: | ||
end | end | ||
if do_link then | if do_link then | ||
template = | template = ('[[%s|%s]]'):format(frame:expandTemplate{ title='Transclude', args = {template} }, template) | ||
end | end | ||
table.sort(args) | table.sort(args) | ||
for i = 1, #args do | for i = 1, #args do | ||
local stripped = | local stripped = args[i]:match('^' .. i .. '=([^=]*)$') | ||
if stripped then args[i] = stripped else break end | if stripped then args[i] = stripped else break end | ||
end | end |