Content deleted Content added
prefix .. |
Merge from Module:Navbox with collapsible groups |
||
Line 4:
local inArray = require("Module:TableTools").inArray
local getArgs -- lazily initialized
-- helper functions
local function concatstrings(s)
local r = table.concat(s, '')
if r:match('^%s*$') then r = nil end
return r
end
local function concatstyles(s)
local r = table.concat(s, ';')
while r:match(';%s*;') do
r = mw.ustring.gsub(r, ';%s*;', ';')
end
if r:match('^%s*;%s*$') then r = nil end
return r
end
local function andnum(s, n)
return string.format(cfg.arg[s..'_and_num'], n)
end
local function getSubgroup(args, listnum, listText)
local subArgs = {
[cfg.arg.border] = cfg.keyword.border_subgroup,
[cfg.arg.navbar] = cfg.keyword.navbar_plain
}
local hasSubArgs = false
for k, v in pairs(args) do
k = tostring(k)
for _, w in ipairs(cfg.keyword.subgroups) do
w = w .. listnum .. "_"
if (#k > #w) and (k:sub(1, #w) == w) then
subArgs[k:sub(#w + 1)] = v
hasSubArgs = true
end
end
end
return hasSubArgs and p._navbox(subArgs) or listText
end
local function readArgs(args, prefix)
-- Read the arguments in the order they'll be output in, to make references
-- number in the right order.
local _
_ = args[prefix .. cfg.arg.title]
_ = args[prefix .. cfg.arg.above]
-- Limit this to 20 as covering 'most' cases (that's a SWAG) and because
-- iterator approach won't work here
for i = 1, 20 do
_ = args[prefix .. andnum('group', i)]
if inArray(cfg.keyword.subgroups, args[prefix .. andnum('list', i)]) then
for _, v in ipairs(cfg.keyword.subgroups) do
readArgs(args, prefix .. v .. i .. "_")
end
end
end
_ = args[prefix .. cfg.arg.below]
end
-- Main functions
function p._navbox(args)
local function striped(wikitext, border)
Line 59 ⟶ 117:
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match(cfg.pattern.nowrap) then
line = string.format(cfg.nowrap_item, prefix, content)
end
table.insert(lines, line)
Line 185 ⟶ 243:
end
local group_and_num =
local groupstyle_and_num =
if args[group_and_num] then
local groupCell = row:tag('th')
Line 230 ⟶ 288:
end
local list_and_num =
local listText = inArray(cfg.keyword.subgroups, args[list_and_num])
and getSubgroup(args, listnum, args[list_and_num]) or args[list_and_num]
local oddEven = cfg.marker.oddeven
Line 258 ⟶ 298:
end
local liststyle_and_num =
local listclass_and_num =
listCell
:css('padding', '0')
Line 567 ⟶ 607:
end
function p.
-- table for args passed to navbox
local targs = {}
-- process args
local passthrough = {
[cfg.arg.border]=true,[cfg.arg.bodyclass]=true,[cfg.arg.groupclass]=true,
[cfg.arg.listclass]=true,[cfg.arg.style]=true,[cfg.arg.bodystyle]=true,
[cfg.arg.basestyle]=true,[cfg.arg.title]=true,[cfg.arg.titleclass]=true,
[cfg.arg.titlestyle]=true,[cfg.arg.above]=true,[cfg.arg.aboveclass]=true,
[cfg.arg.abovestyle]=true,[cfg.arg.below]=true,[cfg.arg.belowclass]=true,
[cfg.arg.belowstyle]=true,[cfg.arg.image]=true,[cfg.arg.imageclass]=true,
[cfg.arg.imagestyle]=true,[cfg.arg.imageleft]=true,[cfg.arg.imageleftstyle]=true
}
for k,v in pairs(pargs) do
if k and type(k) == 'string' then
if passthrough[k] then
targs[k] = v
elseif (k:match(cfg.pattern.num)) then
local n = mw.ustring.gsub(k, cfg.pattern.num, '%1')
local list_and_num = andnum('list', n)
if ((k:match(cfg.pattern.listnum) or k:match(cfg.pattern.contentnum))
and targs[list_and_num] == nil
and pargs[andnum('group', n)] == nil
and pargs[andnum('sect', n)] == nil
and pargs[andnum('section', n)] == nil) then
targs[list_and_num] = concatstrings({
pargs[list_and_num] or '',
pargs[andnum('content', n)] or ''
})
if (targs[list_and_num] and inArray(cfg.keyword.subgroups, targs[list_and_num])) then
targs[list_and_num] = getSubgroup(n, targs[list_and_num])
end
elseif ((k:match(cfg.pattern.groupnum) or k:match(cfg.pattern.sectnum) or k:match(cfg.pattern.sectionnum))
and targs[list_and_num] == nil) then
local titlestyle = concatstyles({
pargs[cfg.arg.groupstyle] or '',
pargs[cfg.arg.secttitlestyle] or '',
pargs[andnum('groupstyle', n)] or '',
pargs[andnum('sectiontitlestyle', n)] or ''
})
local liststyle = concatstyles({
pargs[cfg.arg.liststyle] or '',
pargs[cfg.arg.contentstyle] or '',
pargs[andnum('liststyle', n)] or '',
pargs[andnum('contentstyle', n)] or ''
})
local title = concatstrings({
pargs[andnum('group', n)] or '',
pargs[andnum('sect', n)] or '',
pargs[andnum('section', n)] or ''
})
local list = concatstrings({
pargs[list_and_num] or '',
pargs[andnum('content', n)] or ''
})
if list and inArray(cfg.keyword.subgroups, list) then
list = getSubgroup(n, list)
end
local abbr_and_num = andnum('abbr', n)
local state = (pargs[abbr_and_num] and pargs[abbr_and_num] == pargs[cfg.arg.selected])
and cfg.keyword.state_uncollapsed
or (pargs[andnum('state', n)] or cfg.keyword.state_collapsed)
targs[list_and_num] = Navbox._navbox({
cfg.keyword.border_child,
[cfg.arg.navbar] = cfg.keyword.navbar_plain,
[cfg.arg.state] = state,
[cfg.arg.basestyle] = pargs[cfg.arg.basestyle],
[cfg.arg.title] = title,
[cfg.arg.titlestyle] = titlestyle,
[andnum('list', 1)] = list,
[cfg.arg.liststyle] = liststyle,
[cfg.arg.listclass] = pargs[andnum('listclass', n)],
[cfg.arg.image] = pargs[andnum('image', n)],
[cfg.arg.imageleft] = pargs[andnum('imageleft', n)],
[cfg.arg.listpadding] = pargs[cfg.arg.listpadding]
})
end
end
end
end
-- ordering of style and bodystyle
targs[cfg.arg.style] = concatstyles({targs[cfg.arg.style] or '', targs[cfg.arg.bodystyle] or ''})
targs[cfg.arg.bodystyle] = nil
-- child or subgroup
if targs[cfg.arg.border] == nil then targs[cfg.arg.border] = pargs[1] end
return p._navbox(targs)
end
-- Template entry points
p.navbox = function (frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
Line 593 ⟶ 708:
readArgs(args, "")
return p._navbox(args)
end
p['with collapsible groups'] = function (frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {wrappers = {cfg.pattern.navbox_coll_groups}})
readArgs(args, "")
return p._withCollapsibleGroups(args)
end
|