Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Compact list
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local getArgs = require('Module:Arguments').getArgs local clist = require('Module:Collapsible list').main local compressSparseArray = require('Module:TableTools').compressSparseArray local p = {} --[[ Combine named-and-numbered arguments into a pretty list. "Named-and-numbered" means foo, foo0, foo_1, foo234: anything that matches foo_?%d+ Arguments: args[1] = name to search arguments rest of args = arguments to search Returns: Pretty list, in order of argument number. "foo" comes first, then "foo0", "foo1", ... "fooN" The argument numbering does not have to be sequential If number of args that match <= args[_limit] (4 default), returns text list of the form "A, B, C and D" otherwise returns collapsible list ({{clist}}) --]] function p._main(args) local pattern = "^"..args[1].."_?(%d+)$" -- pattern to match local values = {} for k, v in pairs(args) do --- loop through all arguments if k == args[1] then --- if argument is just "foo", put it first values[1] = v else ord = tonumber(mw.ustring.match(k,pattern)) --- if "foo_?%d+", extract number if ord then values[ord+2] = v --- put value into list at number+2 (to keep "foo" first, even for foo0) end end end values = compressSparseArray(values) --- squeeze out gaps/nils in values, keep ordering local limit = tonumber(args._limit) or 4 if #values > limit then return clist(values) --- if longer than limit, call Module:Collapsible list end return mw.text.listToText(values) --- otherwise just print out pretty text list end function p.main(frame) local args = getArgs(frame) return p._main(args) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Collapsible list
(
edit
)
Template:Enum
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Template:Para
(
edit
)
Template:Tl
(
edit
)
Module:Arguments
(
edit
)
Module:Collapsible list
(
edit
)
Module:Compact list/doc
(
edit
)
Module:Effective protection level
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Yesno
(
edit
)