10,178
edits
Changes
m
local function getListItem -- Detect invalid type attributes and attempt to convert them to -- list-style-type CSS properties. if data.type and not data.listStyleType and not tostring(data, style, itemStyle.type):find('^%s*[1AaIi]%s*$') then data.listStyleType = data.type data.type = nil end end -- List tag type if not listType == 'ordered' or listType == 'horizontal_ordered' then data then.listTag = 'ol' else return nildata.listTag = 'ul'
local item = htmlBuilder.create('li')
item
.cssText(style)
.cssText(itemStyle)
.wikitext(data)
return tostring(item)
end
local function getArgNums(args) -- Returns an array containing the keys of all positional argumentsStart number for ordered lists -- that contain data (i.estart = args. nonstart if listType == 'horizontal_ordered' then -whitespace values)- Apply fix to get start numbers working with horizontal ordered lists. local nums startNum = {} for k, v in pairstonumber(argsdata.start) do if type(k) == 'number' and startNum then k >= 1 and mathdata.floor(k) =counterReset = k and mw.ustring.match(v, '%Slistitem ') then table.insert. tostring(nums, kstartNum - 1)
root-- Render the list tag.cssText(args.style) local list = root.:tag((listType == 'ordered' or listType == 'horizontal_ordered') and 'ol' data.listTag or 'ul')
.:attr('{start', args= data.start) .attr(', type', args= data.type)} .:css({ ['listcounter-style-typereset'] = data.counterReset, args ['list-style-type'])= data.listStyleType } if data.listStyle then list:cssText(args.list_style or args.ul_style or argsdata.ol_stylelistStyle) end -- ul_style and ol_style are included Render the list items for backwards compatibilityi, t in ipairs(data. No distinction is made for ordered items or unordered lists{}) do local item = list:tag('li') if data.itemStyle then item:cssText(data.itemStyle) end if t.style then item:cssText(t.style) end item :attr{value = t.value} :wikitext(tablet.concat(listItems)content) end
local function makeWrapperp.renderTrackingCategories(listTypeargs) return functionlocal isDeprecated = false -- Tracks deprecated parameters. for k, v in pairs(frameargs)do local origArgsk = tostring(k) if frame k:find('^item_style%d+$') or k:find('^item_value%d+$') then isDeprecated =true break end end local ret = mw'' if isDeprecated then ret = ret .. '[[Category:List templates with deprecated parameters]]' end return retend function p.getCurrentFramemakeList(listType, args) if not listType or not listTypes[listType] then error(string.format( origArgs "bad argument #1 to 'makeList' ('%s' is not a valid list type)", tostring(listType) ), 2) end checkType('makeList', 2, args, 'table') local data = p.makeListData(listType, args) local list = frame:getParentp.renderList(data) local trackingCategories = p.renderTrackingCategories(args) return list .. trackingCategoriesend for k, v listType in pairs(listTypes) do p[listType] = function (frame.args) do local mArguments = require('Module:Arguments') local origArgs = mArguments.getArgs(frame, { valueFunc = function (key, value) if not value or not mw.argsustring.find(value, '%S') then return nil end if mw.ustring.find(value, '^%s*[%*#;:]') then return value else breakreturn value:match('^%s*(.-)%s*$')
else origArgs = framereturn nil
if type(k) == 'number' or v ~= '' then args[k] = v end
end
local funcNames = {'bulleted', 'unbulleted', 'horizontal', 'ordered', 'horizontal_ordered'}
for _, funcName in ipairs(funcNames) do
p[funcName] = makeWrapper(funcName)
1 revision imported
-- This module outputs different kinds of lists. At the moment, bulleted, unbulleted,-- unbulleted, horizontal, ordered, and horizontal ordered lists are supported. local libUtil = require('libraryUtil')local checkType = libUtil.checkTypelocal mTableTools = require('Module:TableTools')
local p = {}
local htmlBuilder listTypes = require{ ['bulleted'] = true, ['unbulleted'] = true, ['horizontal'] = true, ['ordered'] = true, ['horizontal_ordered'] = true} function p.makeListData(listType, args) -- Constructs a data table to be passed to p.renderList. local data = {} -- Classes data.classes = {} if listType == 'horizontal' or listType == 'horizontal_ordered' then table.insert(data.classes, 'Module:HtmlBuilderhlist hlist-separated') elseif listType == 'unbulleted' then table.insert(data.classes, 'plainlist') end table.insert(data.classes, args.class) -- Main div style data.style = args.style -- Indent for horizontal lists if listType == 'horizontal' or listType == 'horizontal_ordered' then local indent = tonumber(args.indent) indent = indent and indent * 1.6 or 0 if indent > 0 then data.marginLeft = indent .. 'em' end end -- List style types for ordered lists -- This could be "1, 2, 3", "a, b, c", or a number of others. The list style -- type is either set by the "type" attribute or the "list-style-type" CSS -- property. if listType == 'ordered' or listType == 'horizontal_ordered' then data.listStyleType = args.list_style_type or args['list-style-type'] data.type = args['type']
end
end
end
-- List style -- ul_style and ol_style are included for backwards compatibility. No -- distinction is made for ordered or unordered lists. data.listStyle = args.list_style -- List items -- li_style is included for backwards compatibility. item_style was included -- to be easier to understand for non-coders. 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' .. tostring(num) .. '_style'] or args['item_style' .. tostring(num)] item.value = args['item' .. tostring(num) .. '_value'] or args['item_value' .. tostring(num)] table.sortinsert(numsdata.items, item) end return numsdata
end
function p.makeListrenderList(listType, argsdata) -- This is Renders the main function to be called from other Lua moduleslist HTML. -- First, get Return the blank string if there are no list items. local listItems = {} local argNums = getArgNumsif type(args) for i, num in ipairs(argNumsdata.items) do local item ~= getListItem( args[num], args.item_style or args.li_style, -- li_style is included for backwards compatibility. item_style was included to be easier to understand for non-coders. args['item_styletable' .. tostring(num)] or args['li_style' #data.. tostring(num)] ) table.insert(listItems, item) end if #listItems == 0 items < 1 then
return ''
end
-- Build Render the list htmlmain div tag. local root = htmlBuildermw.html.create('div') if listType == 'horizontal' for i, class in ipairs(data.classes or listType == 'horizontal_ordered' then root.addClass('hlist'{}) elseif listType == 'unbulleted' thendo root.:addClass('plainlist'class)
end
root.addClass(args.class) if listType == :css{['horizontalmargin-left' or listType ] == 'horizontal_ordered' then local indent = argsdata.indent and tonumber(indent)marginLeft} indent = tostring((indent and indent * 1 if data.6) or 0)style then root.css:cssText('margin-left', indent .data. 'em'style)
end
list
return tostring(root)
end
end
end
}) -- Copy all the arguments to a new table, for faster indexing.
local args = {}
for k, v in pairs(origArgs) do
end
return p.makeList(listType, args)
end
end
return p