Module:List: Difference between revisions

285 bytes added ,  1 month ago
m
1 revision imported
Enwikipedia>Mr. Stradivarius
(split the HTML rendering code out into a separate function, add a tracking category for deprecated parameters, ignore blank/whitespace arguments, and replace getArgNums with the equivalent function in Module:TableTools)
m (1 revision imported)
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
(19 intermediate revisions by 15 users not shown)
Line 1:
-- This module outputs different kinds of lists. At the moment, bulleted,
-- unbulleted, horizontal, ordered, and horizontal ordered lists are supported.
 
local libUtil = require('libraryUtil')
local checkType = libUtil.checkType
Line 20 ⟶ 17:
local data = {}
 
-- Classes and TemplateStyles
data.classes = {}
data.templatestyles = ''
if listType == 'horizontal' or listType == 'horizontal_ordered' then
table.insert(data.classes, 'hlist')
data.templatestyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Hlist/styles.css' }
}
elseif listType == 'unbulleted' then
table.insert(data.classes, 'plainlist')
data.templatestyles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Plainlist/styles.css' }
}
end
table.insert(data.classes, args.class)
Line 80 ⟶ 84:
-- ul_style and ol_style are included for backwards compatibility. No
-- distinction is made for ordered or unordered lists.
data.listStyle = args.list_style or args.ul_style or args.ol_style
 
-- List items
Line 87 ⟶ 91:
data.itemStyle = args.item_style or args.li_style
data.items = {}
for i_, num in ipairs(mTableTools.numKeys(args)) do
local item = {}
item.content = args[num]
item.style = args['item_styleitem' .. tostring(num) .. '_style']
or args['li_styleitem_style' .. tostring(num)]
item.value = args['item_valueitem' .. tostring(num) .. '_value']
or args['item_value' .. tostring(num)]
table.insert(data.items, item)
end
Line 109 ⟶ 114:
-- Render the main div tag.
local root = mw.html.create('div')
for i_, class in ipairs(data.classes or {}) do
root:addClass(class)
end
Line 130 ⟶ 135:
 
-- Render the list items
for i_, t in ipairs(data.items or {}) do
local item = list:tag('li')
if data.itemStyle then
Line 143 ⟶ 148:
end
 
return data.templatestyles .. tostring(root)
end
 
function p.renderTrackingCategories(args)
local isDeprecated = false -- Tracks deprecated parameters.
for ik, paramv in ipairs{'ul_style', 'ol_style', 'li_style'}pairs(args) do
k = tostring(k)
if args[param] then
if k:find('^item_style%d+$') or k:find('^li_styleitem_value%d+$') then
isDeprecated = true
break
end
end
if not isDeprecated then
for k, v in pairs(args) do
k = tostring(k)
if k:find('^item_style%d+$') or k:find('^li_style%d+$') then
isDeprecated = true
break
end
end
end
Line 187 ⟶ 184:
p[listType] = function (frame)
local mArguments = require('Module:Arguments')
local origArgs = mArguments.getArgs(frame), {
valueFunc = function (key, value)
if not value or not mw.ustring.find(value, '%S') then return nil end
if mw.ustring.find(value, '^%s*[%*#;:]') then
return value
endelse
return value:match('^%s*(.-)%s*$')
end
return nil
end
})
-- Copy all the arguments to a new table, for faster indexing.
local args = {}