Module:Navbox: Difference between revisions

No change in size ,  10 years ago
apparently none of the test cases test tracking categories. fix a bunch of script errors
Enwikipedia>Jackmcbarn
(don't use globals)
Enwikipedia>Jackmcbarn
(apparently none of the test cases test tracking categories. fix a bunch of script errors)
Line 256:
-- Tracking categories
--
local function renderTrackingCategories(builder)
local frame = mw.getCurrentFrame()
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
 
local function getTrackingCategories()
local cats = {}
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
return cats
end
 
local function needsHorizontalLists()
Line 295 ⟶ 274:
end
 
local function getTrackingCategories()
local cats = {}
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
return cats
end
 
local function renderTrackingCategories(builder)
local frame = mw.getCurrentFrame()
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
 
--