Module:Caselist
| This Lua module is used on approximately 1,300 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements Template:Caselist. See the template page for documentation.
-- This module implements {{caselist}}.
local mNavbox = require('Module:Navbox')
local p = {}
local function wraplinks(s)
-- add allow wrap
if s and not mw.ustring.match(s, '<span class="wrap">') then
-- probably a more efficient way to match 40 or more characters
local m = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]'
m = m .. m .. m .. m
m = m .. m
s = mw.ustring.gsub(s,
'%[%[(' .. m .. '[^%[%]<>|]*)%]%]',
'[[%1|<span class="wrap">%1</span>]]')
s = mw.ustring.gsub(s,
'%[%[([^%[%]<>|]*)|(' .. m .. '[^%[%]<>|]*)%]%]',
'[[%1|<span class="wrap">%2</span>]]')
end
return s
end
function p._main(args)
local nargs = {} -- Navbox args
-- Cases
do
local caseNums = {}
for k in pairs(args) do
if type(k) == 'string' then
local num = k:match('^case([1-9][0-9]*)$')
if num then
table.insert(caseNums, tonumber(num))
end
end
end
if #caseNums < 1 then
error("no 'case1', 'case2', etc. parameters specified in [[Template:Caselist]]", 2)
end
table.sort(caseNums)
for i, num in ipairs(caseNums) do
nargs['list' .. tostring(i)] = wraplinks(args['case' .. tostring(num)])
end
end
-- Other args
nargs.name = args.name or 'Caselist'
nargs.navbar = args.navbar or 'top'
nargs.style = string.format(
'width: %s; text-align: %s; font-size: 80%%; line-height: 1.5em; background-color: #fafafa; %s',
args.width or '350px',
args.textalign or 'center',
args.align == 'left'
and 'float: left; clear: left; margin: 0 1em 1em 0;'
or 'float: right; clear: right; margin: 0 0 1em 1em;'
)
nargs.evenodd = 'off'
nargs.title = args.title or args.name or error(
"no 'title' or 'name' parameters specified in [[Template:Caselist]]",
2
)
nargs.below = args.notes or args.below
nargs.tracking = 'no'
return mNavbox._navbox(nargs)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Caselist'
})
return p._main(args)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.