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

پرش به ناوبری پرش به جستجو
۵۳۵ بایت اضافه‌شده ،  ‏۱۶ سپتامبر ۲۰۲۱
update
جز (۱ نسخه واردشده)
ویکی حقوق>Jeeputer
(update)
خط ۱: خط ۱:
require('Module:No globals');
require('Module:No globals');


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>';
local error_msg = '<span style=\"font-size:100%\" class=\"error\">پارامتر <code style=\"color:inherit; border:inherit; padding:inherit;\">&#124;_template=</code> ناموجود یا خالی</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 = alias_pair:match ('(.-)%s*:%s*(.+)'); -- from each pair, get local and target parameter names
l_name, t_name = mw.ustring.match (alias_pair, '(.-)%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 tonumber (l_name) then
if mw.getContentLanguage():parseFormattedNumber(l_name) then
l_name = tonumber (l_name); -- convert number-as-text to a number
l_name = mw.getContentLanguage():parseFormattedNumber(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[alias_map[k..'#']:gsub('#', '')] = v; -- remove '#' and copy parameter to pframe_args table
pframe_args[mw.ustring.gsub(alias_map[k..'#'], '#', '')] = v; -- remove '#' and copy parameter to pframe_args table
pframe_args[k] = nil; -- unset the alias
pframe_args[k] = nil; -- unset the alias
elseif k:match ('%d+') then -- if this parameter name contains digits
elseif mw.ustring.match (k, '%d+') then -- if this parameter name contains digits
local temp = k:gsub ('%d+', '#'); -- make a copy; digits replaced with single '#'
local temp = mw.ustring.gsub (k, '%d+', '#'); -- make a copy; digits replaced with single '#'
local enum = k:match ('%d+'); -- get the enumerator
local enum = mw.ustring.match (k, '%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[alias_map[temp]:gsub('#', enum)] = v; -- use canonical name and replace '#' with enumerator and add to pframe_args
pframe_args[mw.ustring.gsub(alias_map[temp], '#', 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
خط ۲۴۹: خط ۲۴۹:
]]
]]


local function list(frame, do_link)
local args = {}; -- table of default and live parameters and their values to be passed to the listed template
local template; -- the name of the listed template


local function list (frame)
template = _main (frame, args, true); -- get default and live parameters and the name of the listed template
local args = {}; -- table of default and live parameters and their values to be passed to the listed template
if not template then -- template name is required
local template; -- the name of the listed template
return error_msg; -- emit error message and abandon if template name not present
 
end
template = _main (frame, args, true); -- get default and live parameters and the name of the listed template
if do_link then
if not template then -- template name is required
template = mw.ustring.format(('[[%s|%s]]'), frame:expandTemplate{ title='Transclude', args = {template} }, template)
return error_msg; -- emit error message and abandon if template name not present
end
table.sort(args)
for i = 1, #args do
local stripped = mw.ustring.match(args[i], '^' .. i .. '=([^=]*)$')
if stripped then args[i] = stripped else break end
end
end
return frame:preprocess(table.concat({
'<code style="color:inherit; background:inherit; border:none;">&#123;&#123;',
template,
('<wbr><nowiki>|%s</nowiki>'):rep(#args):format(unpack(args)), '&#125;&#125;</code>'})); -- render the template
end


return frame:preprocess (table.concat ({'<code style="color:inherit; background:inherit; border:none;"><nowiki>{{', template, ' |', table.concat( args, ' |' ), '}}</nowiki></code>'})); -- render the template
local function link (frame)
return list(frame, true)
end
end


--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
خط ۲۶۷: خط ۲۷۹:


return {
return {
link = link,
list = list,
list = list,
wrap = wrap,
wrap = wrap,
};
};
کاربر ناشناس

منوی ناوبری