Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Neighbors
Esassani
Mobai
Glenn
Mors
Creatures
Fish
Insects
Shore-Dwellers
Search
Search
English
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Card List
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
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 p = {} local lib = require('Module:Feature') local Card = require('Module:Card')._main function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { parentFirst = true, removeBlanks = false, wrapper = { 'Template:Card List' } }) return p._main(args) end function p.splitNote(entry, notePattern) if notePattern then item, note = entry:match(notePattern) if item == nil then -- will be nil if note is not present return entry end return item, note end return entry end function p.splitParams(entry, paramDelim) if entry:find('{.-}') then local params = string.match(entry, '{(.-)}') entry = entry:gsub('{.-}', '') params = lib.split(params, paramDelim) local returns = {} for i, param in ipairs(params) do local name, val = string.match(param, '^%s*(.-)%s*=%s*(.-)%s*$') if name ~= nil and name ~= '' and val ~= nil then --named params returns[name] = val elseif param ~= nil and param ~= '' then --unnamed params table.insert(returns, param) end end return entry, returns end return entry, {} end -- all the non-boolean params except note_delim local PARAMS_NOT_SUPPORTING_BLANKS = {"caption", "amount", "delim", "amount_delim", "type", "caption_width"} function p._main(args) local input = args[1] or '' local itemDelim = args.delim or ',' local countDelim = args.amount_delim or '*' local noteDelim = args.note_delim or '/' local paramDelim = args.param_delim or '$' --= handle blanks for non-boolean params for _, paramName in ipairs(PARAMS_NOT_SUPPORTING_BLANKS) do local value = args[paramName] if value == "" then args[paramName] = nil end end -- put all text after the first noteDelim into the second capture local notePattern if lib.isNotEmpty(noteDelim) then notePattern = "^(.-)" .. noteDelim .. "(.*)$" end local containerClass = "card-list-container " if args.mobile_list then containerClass = containerClass .. "card-mobile-list " end if lib.isNotEmpty(args.class) then containerClass = containerClass .. args.class end local result = mw.html.create():tag("span"):addClass(containerClass) local categories = mw.html.create() local splitSett = { noTrim = args.trim and false or true, removeEmpty = args.removeEmpty and true or false } for entry in lib.gsplit(input, itemDelim, splitSett) do if not lib.isEmpty(entry) then local entry, cardArgs = p.splitParams(entry, paramDelim) --check for entry-specific params local item, note = p.splitNote(entry, notePattern) --check for entry-specific note local item_parts = lib.split(item, countDelim) --check for entry-specific amount local name = item_parts[1] local amount = item_parts[2] if args.ts and tonumber(amount) ~= nil then amount = lib.thousandsSeparator(amount) end --set card arguments without replacing those set by entry-specific params cardArgs = p.assignArgs(cardArgs, args, name, amount, note) -- mw.logObject(cardArgs) result:node(Card(cardArgs)) if (args.category ~= nil) then if type(args.category) ~= 'table' then args.category = {args.category} end for _, catForm in ipairs(args.category) do categories:wikitext('[[Category:', catForm:gsub('{item}', cardArgs.name), ']]') end end end end if (args.category ~= nil) then result:node(require('Module:Namespace detect')._main({ main = categories })) end return result end function p.list(args) args = args or {} --= handle blanks for non-boolean params for _, paramName in ipairs(PARAMS_NOT_SUPPORTING_BLANKS) do local value = args[paramName] if value == "" then args[paramName] = nil end end local containerClass = "card-list-container" if args.mobile_list then containerClass = containerClass .. " card-mobile-list" end local result = mw.html.create():tag("span"):addClass(containerClass) local categories = mw.html.create() for i, cardArgs in ipairs(args) do if not lib.isEmpty(cardArgs) then if type(cardArgs) == 'string' then cardArgs = {cardArgs} end cardArgs = p.assignArgs(cardArgs, args) if (args.category ~= nil) then if type(args.category) ~= 'table' then args.category = {args.category} end for _, catForm in ipairs(args.category) do categories:wikitext('[[Category:', catForm:gsub('{item}', cardArgs.name), ']]') end end result:node(Card(cardArgs)) end end if (args.category ~= nil) then result:node(require('Module:Namespace detect')._main({ main = categories })) end return result end function p.assignArgs(cardArgs, args, name, amount, note) local finalArgs = cardArgs or {} local assignVals = { -- 1 = cardArgs; 2 = args; 0 = param name ['name'] = { {1, '1'}, name }, ['text'] = { {1, '2'}, amount, {2, 0}, {2, 'amount'} }, ['caption'] = { {2, 0} }, ['show_caption'] = { {2, 0} }, ['caption_width'] = { {2, 0} }, ['note'] = { note }, ['stars'] = { {2, 0} }, ['type'] = { {2, 0} }, ['suffix'] = { {2, 0} }, ['set'] = { {2, 0} }, ['mini'] = { {2, 0} }, ['mobile_list'] = { {2, 0} }, ['link'] = { pref = args.link_prefix, suff = args.link_suffix }, ['nolink'] = { {2, 0} }, --icon ['icon'] = { {2, 0} }, ['icon_type'] = { {2, 0} }, ['icon_size'] = { {2, 0} }, ['icon_suffix'] = { {2, 0} }, ['icon_link'] = { pref = args.icon_link_prefix, suff = args.icon_link_suffix }, --icon_right ['icon_right'] = { {2, 0} }, ['icon_right_type'] = { {2, 0} }, ['icon_right_size'] = { {2, 0} }, ['icon_right_suffix'] = { {2, 0} }, ['icon_right_link'] = { pref = args.icon_right_link_prefix, suff = args.icon_right_link_suffix }, --icon_bottom_left ['icon_bottom_left'] = { {2, 0} }, ['icon_bottom_left_type'] = { {2, 0} }, ['icon_bottom_left_size'] = { {2, 0} }, ['icon_bottom_left_suffix'] = { {2, 0} }, ['icon_bottom_left_link'] = { pref = args.icon_bottom_left_link_prefix, suff = args.icon_bottom_left_link_suffix }, --icon_bottom_right ['icon_bottom_right'] = { {2, 0} }, ['icon_bottom_right_type'] = { {2, 0} }, ['icon_bottom_right_size'] = { {2, 0} }, ['icon_bottom_right_suffix'] = { {2, 0} }, ['icon_bottom_right_link'] = { pref = args.icon_bottom_right_link_prefix, suff = args.icon_bottom_right_link_suffix }, } local st = {cardArgs, args} for param, list in pairs(assignVals) do if lib.isNotEmpty(list) and type(list) == 'table' then local paramF if lib.isNotEmpty(cardArgs[param]) then paramF = cardArgs[param] elseif #list > 0 then local i = 0 while i < #list do i = i+1 local val = list[i] if type(val) == 'string' and lib.isNotEmpty(val) then paramF = val break elseif type(val) == 'table' and lib.isNotEmpty(st[val[1]][(val[2]==0 and param or val[2])]) then paramF = st[val[1]][(val[2]==0 and param or val[2])] break end end end if paramF then finalArgs[param] = table.concat({ lib.ternary(lib.isNotEmpty(list.pref) and type(list.pref) == 'string', list.pref, ''), paramF, lib.ternary(lib.isNotEmpty(list.suff) and type(list.suff) == 'string', list.suff, '') }, '') end end end return finalArgs end return p
Summary:
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Petit Planet:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Below are commonly used wikitext from
MediaWiki:Edittools
. Click on any to insert them in the edit box.
File Pages
==Summary==
==Licensing==
{{Fairuse}}
{{File|}}
Dynamic Page List
¦
²
«
»
²{¦}²
«»
«/»
«!----»
Array in DPL
¹
^2{
}^2
^2{¹}^2
Parser Functions
{{#if:||}}
{{#if:<condition>|<result if true>|<result if false>}}
{{#ifeq:|||}}
{{#ifeq:<text1>|<text2>|<result if text1=text2>|<result if text1≠text2>}}
{{#expr:}}
{{#expr:<mathematical expression>}}
{{#switch:||#default=}}
{{#switch:<text1>|<text2>=<result if text1=text2>|<text3>=<result if text1=text3>|#default=<result if no valid match>}}
{{#replace:||}}
{{#replace:<text1>|<plain text to find in text1>|<plain text to insert in place of the text found>}}
{{#titleparts:}}
{{#replace:<page name>}}
{{#tag:|}}
{{#tag:<name of html tag>|<content inside html tag>}}
Markup
{{}}
|
[]
[[]]
[[Category:]]
#REDIRECT [[]] [[Category:Redirect Pages]]
<code></code>
<includeonly></includeonly>
<noinclude></noinclude>
<nowiki></nowiki>
<!---->
<br>
§
Notices
{{Stub|}}
{{Stub Dialogue}}
{{Upcoming}}
{{Under Construction}}
{{Placeholder|}}
Magic Words
{{!}}
{{formatnum:}}
{{lc:}}
{{uc:}}
{{PAGENAME}}
{{FULLPAGENAME}}
{{ROOTPAGENAME}}
{{BASEPAGENAME}}
{{SUBPAGENAME}}
{{DISPLAYTITLE:|noreplace}}
__TOC__
__NOTOC__
__EXPECTUNUSEDCATEGORY__
__HIDDENCAT__
HTML Entities
—
,
­
Template used on this page:
Module:Card List/doc
(
edit
)