Module:List: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
m (Protected Module:List: High-risk Lua module: ~1,100 transclusions ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))) |
(add fix to make the start parameter work with horizontal ordered lists, and switch to Module:Arguments for argument processing) |
||
Line 4: | Line 4: | ||
local p = {} |
local p = {} |
||
local getArgs = require('Module:Arguments').getArgs |
|||
local htmlBuilder = require('Module:HtmlBuilder') |
local htmlBuilder = require('Module:HtmlBuilder') |
||
Line 22: | Line 23: | ||
local function getArgNums(args) |
local function getArgNums(args) |
||
-- Returns an array containing the keys of all positional arguments |
-- Returns an array containing the keys of all positional arguments that contain data (i.e. non-whitespace values). |
||
-- that contain data (i.e. non-whitespace values). |
|||
local nums = {} |
local nums = {} |
||
for k, v in pairs(args) do |
for k, v in pairs(args) do |
||
Line 84: | Line 84: | ||
-- Build the list tags and list items. |
-- Build the list tags and list items. |
||
local list = root.tag((listType == 'ordered' or listType == 'horizontal_ordered') and 'ol' or 'ul') |
local list = root.tag((listType == 'ordered' or listType == 'horizontal_ordered') and 'ol' or 'ul') |
||
⚫ | |||
list |
|||
.attr('start', start) |
|||
if listType == 'horizontal_ordered' then |
|||
-- Apply fix to get start numbers working with horizontal ordered lists. |
|||
local startNum = tonumber(start) |
|||
if startNum then |
|||
list.css('counter-reset', 'listitem ' .. tostring(startNum - 1)) |
|||
⚫ | |||
⚫ | |||
list |
list |
||
⚫ | |||
.attr('type', typeAttr) |
.attr('type', typeAttr) |
||
.css('list-style-type', listStyleType) |
.css('list-style-type', listStyleType) |
||
Line 95: | Line 104: | ||
local function makeWrapper(listType) |
local function makeWrapper(listType) |
||
return function(frame) |
return function(frame) |
||
local |
local args = getArgs(frame, { |
||
valueFunc = function (key, value) |
|||
if frame == mw.getCurrentFrame() then |
|||
⚫ | |||
origArgs = frame:getParent().args |
|||
return value |
|||
for k, v in pairs(frame.args) do |
|||
⚫ | |||
origArgs = frame.args |
|||
break |
|||
end |
end |
||
}) |
|||
origArgs = frame |
|||
⚫ | |||
local args = {} |
|||
for k, v in pairs(origArgs) do |
|||
⚫ | |||
args[k] = v |
|||
⚫ | |||
⚫ | |||
return p.makeList(listType, args) |
return p.makeList(listType, args) |
||
end |
end |