Module:Navbox: Difference between revisions
add tracking categories
m>Toohool (add comment) |
m>Toohool (add tracking categories) |
||
Line 8: | Line 8: | ||
local args | local args | ||
local frame | |||
local tableRowAdded = false | local tableRowAdded = false | ||
local border | local border | ||
Line 256: | Line 257: | ||
.wikitext(args.image) | .wikitext(args.image) | ||
end | end | ||
end | |||
-- | |||
-- Tracking categories | |||
-- | |||
function renderTrackingCategories(builder) | |||
if not frame then return end | |||
local s = frame:preprocess('{{#ifeq:{{NAMESPACE}}|{{ns:10}}|1|0}}{{SUBPAGENAME}}') | |||
if mw.ustring.sub(s, 1, 1) == '0' then return end -- not in template space | |||
local subpage = mw.ustring.lower(mw.ustring.sub(s, 2)) | |||
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end | |||
for i, cat in ipairs(getTrackingCategories()) do | |||
builder.wikitext('[[Category:' .. cat .. ']]') | |||
end | |||
end | |||
function getTrackingCategories() | |||
local cats = {} | |||
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end | |||
if hasCustomListSpacing() then table.insert(cats, 'Navigational boxes with custom list spacing') end | |||
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colors') end | |||
end | |||
function needsHorizontalLists() | |||
if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end | |||
local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist vcard', 'vcard hlist'} | |||
for i, cls in ipairs(listClasses) do | |||
if args.listclass == cls or args.bodyclass == cls then | |||
return false | |||
end | |||
end | |||
return true | |||
end | |||
function hasCustomListSpacing() | |||
return args.liststyle == 'padding: 0.25em 0; line-height: 1.3em;' or | |||
args.liststyle == 'padding:0.25em 0; line-height:1.4em; width:auto;' or | |||
args.liststyle == 'padding:0.4em 0; line-height:1.4em;' | |||
end | |||
function hasBackgroundColors() | |||
return args.titlestyle or args.groupstyle | |||
end | end | ||
Line 339: | Line 387: | ||
end | end | ||
renderTrackingCategories(res) | |||
return tostring(res) | return tostring(res) | ||
end | end | ||
function p.navbox(frame | function p.navbox(frm) | ||
frame = frm | |||
return p._navbox(frame:getParent().args) | return p._navbox(frame:getParent().args) | ||
end | end | ||
return p | return p |