Module:Navbox: Difference between revisions
update from Module:Navbox/sandbox per Template talk:Navbox#Merging nowrap navbox to implement nowrapitems=yes to nowrap listN + above + below text
m>Johnuniq (update from Module:Navbox/sandbox per talk; this implements automatic striping that applies to a navbox and any subgroup (child) navboxes it contains) |
m>Johnuniq (update from Module:Navbox/sandbox per Template talk:Navbox#Merging nowrap navbox to implement nowrapitems=yes to nowrap listN + above + below text) |
||
Line 57: | Line 57: | ||
end | end | ||
local function | local function processItem(item, nowrapitems) | ||
if | if item:sub(1, 2) == '{|' then | ||
-- Applying nowrap to lines in a table does not make sense. | |||
-- Add newlines to compensate for trim of x in |parm=x in a template. | |||
return | return '\n' .. item ..'\n' | ||
end | |||
if nowrapitems == 'yes' then | |||
local lines = {} | |||
for line in (item .. '\n'):gmatch('([^\n]*)\n') do | |||
local prefix, content = line:match('^([*:;#]+)%s*(.*)') | |||
if prefix and not content:match('^<span class="nowrap">') then | |||
line = prefix .. '<span class="nowrap">' .. content .. '</span>' | |||
end | |||
table.insert(lines, line) | |||
end | |||
item = table.concat(lines, '\n') | |||
end | |||
if item:match('^[*:;#]') then | |||
return '\n' .. item ..'\n' | |||
end | end | ||
return item | |||
end | end | ||
Line 139: | Line 154: | ||
:css('font-size', '114%') | :css('font-size', '114%') | ||
:css('margin', '0 4em') | :css('margin', '0 4em') | ||
:wikitext( | :wikitext(processItem(args.title)) | ||
end | end | ||
Line 164: | Line 179: | ||
:attr('colspan', getAboveBelowColspan()) | :attr('colspan', getAboveBelowColspan()) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.above, args.nowrapitems)) | ||
end | end | ||
Line 178: | Line 193: | ||
:attr('colspan', getAboveBelowColspan()) | :attr('colspan', getAboveBelowColspan()) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.below, args.nowrapitems)) | ||
end | end | ||
Line 197: | Line 212: | ||
:attr('rowspan', 2 * #listnums - 1) | :attr('rowspan', 2 * #listnums - 1) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.imageleft)) | ||
end | end | ||
Line 257: | Line 272: | ||
:tag('div') | :tag('div') | ||
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | :css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | ||
:wikitext( | :wikitext(processItem(listText, args.nowrapitems)) | ||
if index == 1 and args.image then | if index == 1 and args.image then | ||
Line 269: | Line 284: | ||
:attr('rowspan', 2 * #listnums - 1) | :attr('rowspan', 2 * #listnums - 1) | ||
:tag('div') | :tag('div') | ||
:wikitext( | :wikitext(processItem(args.image)) | ||
end | end | ||
end | end | ||
Line 325: | Line 340: | ||
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end | if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end | ||
for | for _, cat in ipairs(getTrackingCategories()) do | ||
builder:wikitext('[[Category:' .. cat .. ']]') | builder:wikitext('[[Category:' .. cat .. ']]') | ||
end | end | ||
Line 371: | Line 386: | ||
args = navboxArgs | args = navboxArgs | ||
for k, | for k, _ in pairs(args) do | ||
local listnum = | if type(k) == 'string' then | ||
local listnum = k:match('^list(%d+)$') | |||
if listnum then table.insert(listnums, tonumber(listnum)) end | |||
end | |||
end | end | ||
table.sort(listnums) | table.sort(listnums) |