Module:Infobox: Difference between revisions
Jump to navigation
Jump to search
Infobox>Frietjes |
No edit summary |
||
(39 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
local p = {}; | |||
local p = {} | |||
local | local yesno = require('Module:Yesno') | ||
local args = | local function _renderLine( frame, args, i ) | ||
local | if args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] == '-' then | ||
local | return '' | ||
elseif args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] ~= '' then | |||
local style = ( args[ 'стиль_заголовков' ] or '' ) .. ( args[ 'стиль_заголовка' .. i ] or '' ); | |||
local class = ( args[ 'класс' .. i ] or '' ); | |||
return '\n<tr>\n<th colspan="2" scope="colgroup" class="infobox-header ' .. class .. '" style="' .. style .. '">' .. | |||
args[ 'заголовок' .. i ] .. | |||
'</th>\n</tr>'; | |||
end | |||
if args[ 'блок' .. i ] and args[ 'блок' .. i ] ~= '' then | |||
return args[ 'блок' .. i ]; | |||
end | |||
local | local text = args[ 'текст' .. i ] or ''; | ||
if args[ 'викиданные' .. i ] and args[ 'викиданные' .. i ] ~= '' then | |||
text = frame:expandTemplate{ title = 'Wikidata', args = { | |||
args[ 'викиданные' .. i ], | |||
text, | |||
from = args[ 'from' ] or '' | |||
} }; | |||
end | |||
end | |||
if text ~= '' then | |||
local label = args[ 'метка' .. i ] or ''; | |||
if | |||
local | local class = args[ 'класс' .. i ] or ''; | ||
if string.find(class, 'noplainlist') == nil and string.find(class, 'nofirstlevel') == nil then | |||
class = class .. ' plainlist'; | |||
end | |||
if class ~= '' then | |||
class = ' class="' .. class .. '"'; | |||
end | |||
end | |||
local | local style = ( args[ 'стиль_текстов' ] or '' ) .. ( args[ 'стиль_текста' ] or '' ) .. ( args[ 'стиль_текста' .. i ] or '' ); | ||
if label == '' then | |||
style = 'text-align:center;' .. style; | |||
end | |||
if style ~= '' then | |||
style = ' style="' .. style .. '"'; | |||
end | |||
end | |||
if label ~= '' then | |||
local labelClass = args[ 'класс_меток' ] or ''; | |||
if string.find(labelClass, 'noplainlist') == nil and string.find(labelClass, 'nofirstlevel') == nil then | |||
labelClass = labelClass .. ' plainlist'; | |||
end | |||
if labelClass ~= '' then | |||
labelClass = ' class="' .. labelClass .. '"'; | |||
end | |||
local labelStyle = ( args[ 'стиль_меток' ] or '' ) .. ( args[ 'стиль_метки' .. i ] or '' ); | |||
if labelStyle ~= '' then | |||
labelStyle = ' style="' .. labelStyle .. '"'; | |||
end | |||
end | |||
return '\n<tr>\n<th scope="row"' .. labelClass .. labelStyle .. '>' .. label .. '</th>' .. | |||
'\n<td' .. class .. style .. '>\n' .. text .. '</td>\n</tr>'; | |||
end | |||
return '\n<tr>\n<td colspan="2"' .. class .. style .. '>\n' .. text .. '</td>\n</tr>'; | |||
end | |||
return ''; | |||
end | end | ||
local function | local function maxNumber ( args ) | ||
local maxNumber = 0 | |||
for argName, _ in pairs(args) do | |||
local argNumber = mw.ustring.match(argName, '^[^0-9]+([0-9]+)$') | |||
if argNumber and tonumber(argNumber) > maxNumber then | |||
maxNumber = tonumber(argNumber) | |||
end | |||
end | |||
return maxNumber | |||
end | end | ||
function p.renderLine( frame ) | |||
local args = frame:getParent().args; | |||
return _renderLine(frame, args, '') | |||
end | end | ||
function p.renderLines( frame ) | |||
local args = frame:getParent().args; | |||
local res = '' | |||
local header, text = '', '' | |||
local autoHeaders = yesno(args [ 'автозаголовки' ] or 'false', false) | |||
for i = 1, maxNumber(args) do | |||
if args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] ~= '' then | |||
if text ~= '' or not autoHeaders then | |||
res = res .. header .. text | |||
end | |||
header, text = _renderLine(frame, args, i), '' | |||
else | |||
text = text .. _renderLine(frame, args, i) | |||
end | |||
end | |||
if text ~= '' or not autoHeaders then | |||
res = res .. header .. text | |||
end | |||
return res | |||
end | end | ||
return p; | |||
return p |
Latest revision as of 00:08, 28 September 2025
Documentation for this module may be created at Module:Infobox/doc
local p = {};
local yesno = require('Module:Yesno')
local function _renderLine( frame, args, i )
if args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] == '-' then
return ''
elseif args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] ~= '' then
local style = ( args[ 'стиль_заголовков' ] or '' ) .. ( args[ 'стиль_заголовка' .. i ] or '' );
local class = ( args[ 'класс' .. i ] or '' );
return '\n<tr>\n<th colspan="2" scope="colgroup" class="infobox-header ' .. class .. '" style="' .. style .. '">' ..
args[ 'заголовок' .. i ] ..
'</th>\n</tr>';
end
if args[ 'блок' .. i ] and args[ 'блок' .. i ] ~= '' then
return args[ 'блок' .. i ];
end
local text = args[ 'текст' .. i ] or '';
if args[ 'викиданные' .. i ] and args[ 'викиданные' .. i ] ~= '' then
text = frame:expandTemplate{ title = 'Wikidata', args = {
args[ 'викиданные' .. i ],
text,
from = args[ 'from' ] or ''
} };
end
if text ~= '' then
local label = args[ 'метка' .. i ] or '';
local class = args[ 'класс' .. i ] or '';
if string.find(class, 'noplainlist') == nil and string.find(class, 'nofirstlevel') == nil then
class = class .. ' plainlist';
end
if class ~= '' then
class = ' class="' .. class .. '"';
end
local style = ( args[ 'стиль_текстов' ] or '' ) .. ( args[ 'стиль_текста' ] or '' ) .. ( args[ 'стиль_текста' .. i ] or '' );
if label == '' then
style = 'text-align:center;' .. style;
end
if style ~= '' then
style = ' style="' .. style .. '"';
end
if label ~= '' then
local labelClass = args[ 'класс_меток' ] or '';
if string.find(labelClass, 'noplainlist') == nil and string.find(labelClass, 'nofirstlevel') == nil then
labelClass = labelClass .. ' plainlist';
end
if labelClass ~= '' then
labelClass = ' class="' .. labelClass .. '"';
end
local labelStyle = ( args[ 'стиль_меток' ] or '' ) .. ( args[ 'стиль_метки' .. i ] or '' );
if labelStyle ~= '' then
labelStyle = ' style="' .. labelStyle .. '"';
end
return '\n<tr>\n<th scope="row"' .. labelClass .. labelStyle .. '>' .. label .. '</th>' ..
'\n<td' .. class .. style .. '>\n' .. text .. '</td>\n</tr>';
end
return '\n<tr>\n<td colspan="2"' .. class .. style .. '>\n' .. text .. '</td>\n</tr>';
end
return '';
end
local function maxNumber ( args )
local maxNumber = 0
for argName, _ in pairs(args) do
local argNumber = mw.ustring.match(argName, '^[^0-9]+([0-9]+)$')
if argNumber and tonumber(argNumber) > maxNumber then
maxNumber = tonumber(argNumber)
end
end
return maxNumber
end
function p.renderLine( frame )
local args = frame:getParent().args;
return _renderLine(frame, args, '')
end
function p.renderLines( frame )
local args = frame:getParent().args;
local res = ''
local header, text = '', ''
local autoHeaders = yesno(args [ 'автозаголовки' ] or 'false', false)
for i = 1, maxNumber(args) do
if args[ 'заголовок' .. i ] and args[ 'заголовок' .. i ] ~= '' then
if text ~= '' or not autoHeaders then
res = res .. header .. text
end
header, text = _renderLine(frame, args, i), ''
else
text = text .. _renderLine(frame, args, i)
end
end
if text ~= '' or not autoHeaders then
res = res .. header .. text
end
return res
end
return p;