Module:Navbox: Difference between revisions

669 bytes added ,  7 years ago
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 addNewline(s)
local function processItem(item, nowrapitems)
if s:match('^[*:;#]') or s:match('^{|') then
if item:sub(1, 2) == '{|' then
return '\n' .. s ..'\n'
-- Applying nowrap to lines in a table does not make sense.
else
-- Add newlines to compensate for trim of x in |parm=x in a template.
return s
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(addNewline(args.title))
:wikitext(processItem(args.title))
end
end


Line 164: Line 179:
:attr('colspan', getAboveBelowColspan())
:attr('colspan', getAboveBelowColspan())
:tag('div')
:tag('div')
:wikitext(addNewline(args.above))
:wikitext(processItem(args.above, args.nowrapitems))
end
end


Line 178: Line 193:
:attr('colspan', getAboveBelowColspan())
:attr('colspan', getAboveBelowColspan())
:tag('div')
:tag('div')
:wikitext(addNewline(args.below))
: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(addNewline(args.imageleft))
: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(addNewline(listText))
: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(addNewline(args.image))
: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 i, cat in ipairs(getTrackingCategories()) do
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, v in pairs(args) do
for k, _ in pairs(args) do
local listnum = ('' .. k):match('^list(%d+)$')
if type(k) == 'string' then
if listnum then table.insert(listnums, tonumber(listnum)) end
local listnum = k:match('^list(%d+)$')
if listnum then table.insert(listnums, tonumber(listnum)) end
end
end
end
table.sort(listnums)
table.sort(listnums)
Anonymous user