پرش به محتوا

پودمان:Template wrapper: تفاوت میان نسخه‌ها

Replace Module:No globals with require( "strict" )
جز (۱ نسخه واردشده)
(Replace Module:No globals with require( "strict" ))
خط ۱: خط ۱:
require('Module:No globals');
require('strict');


local error_msg = '<span style=\"font-size:100%\" class=\"error\">پارامتر <code style=\"color:inherit; border:inherit; padding:inherit;\">&#124;_template=</code> ناموجود یا خالی</span>';
local error_msg = '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">&#124;_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 = mw.ustring.match (alias_pair, '(.-)%s*:%s*(.+)'); -- from each pair, get local and target parameter names
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 mw.getContentLanguage():parseFormattedNumber(l_name) then
if tonumber (l_name) then
l_name = mw.getContentLanguage():parseFormattedNumber(l_name); -- convert number-as-text to a number
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[mw.ustring.gsub(alias_map[k..'#'], '#', '')] = v; -- remove '#' and copy parameter to pframe_args table
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 mw.ustring.match (k, '%d+') then -- if this parameter name contains digits
elseif k:match ('%d+') then -- if this parameter name contains digits
local temp = mw.ustring.gsub (k, '%d+', '#'); -- make a copy; digits replaced with single '#'
local temp = k:gsub ('%d+', '#'); -- make a copy; digits replaced with single '#'
local enum = mw.ustring.match (k, '%d+'); -- get the enumerator
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[mw.ustring.gsub(alias_map[temp], '#', enum)] = v; -- use canonical name and replace '#' with enumerator and add to 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: imamatpedia:Templates_for_discussion/Log/2018_April_28#Module:PassArguments
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 = mw.ustring.format(('[[%s|%s]]'), frame:expandTemplate{ title='Transclude', args = {template} }, 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 = mw.ustring.match(args[i], '^' .. i .. '=([^=]*)$')
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
کاربر ناشناس