No edit summary |
No edit summary |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
-- 4: File Suffix (optional) |
-- 4: File Suffix (optional) |
||
-- |
-- |
||
− | -- any characters in the list ' are stripped |
+ | -- any characters in the list ':,. are stripped |
-- |
-- |
||
-- if the item name has "(non digit characters)" at the end, |
-- if the item name has "(non digit characters)" at the end, |
||
-- it is replaced with "-non digit characters" |
-- it is replaced with "-non digit characters" |
||
− | -- |
||
− | -- Plain version is returned if Event version is not in data. |
||
------ |
------ |
||
Line 46: | Line 44: | ||
items = mw.ustring.gsub(items, "^%s*(.-)%s*$", "%1") or '' |
items = mw.ustring.gsub(items, "^%s*(.-)%s*$", "%1") or '' |
||
+ | |||
+ | -- check for !! (! at the end of item) |
||
+ | -- replace with ^! |
||
+ | -- ^ will be replaced back to ! before returning |
||
+ | items = mw.ustring.gsub(items, "!!", "^!") |
||
local itemsFile = "" |
local itemsFile = "" |
||
Line 52: | Line 55: | ||
for it in mw.text.gsplit(items, "%s*!%s*") do |
for it in mw.text.gsplit(items, "%s*!%s*") do |
||
− | local lcIt = mw.ustring.gsub(it, "^([^%(]+)%s%(([^ |
+ | local lcIt = mw.ustring.gsub(it, "^([^%(]+)%s%(([^%d]+)%)$", "%1-%2") |
if not lcIt then lcIt = it end |
if not lcIt then lcIt = it end |
||
− | lcIt = mw.ustring.gsub(mw.ustring.lower(lcIt), "'", "") |
+ | lcIt = mw.ustring.gsub(mw.ustring.lower(lcIt), "[':%,%.]", "") |
itemsFile = itemsFile .. space |
itemsFile = itemsFile .. space |
||
Line 76: | Line 79: | ||
space = " " |
space = " " |
||
end |
end |
||
+ | |||
+ | -- replace back any ! (delimiter) changed earlier |
||
+ | itemsFile = mw.ustring.gsub(itemsFile, "%^", "!") |
||
return itemsFile |
return itemsFile |
||
Line 81: | Line 87: | ||
return p |
return p |
||
+ | |||
+ | -- </nowiki> |
||
+ | -- [[Category:Lua Modules]] |
Revision as of 09:34, 30 June 2020
Description
This module provides display functions for use in other modules.
------
-- LUA script for processing multiple items in a string
-- separated by "!"
--
-- Parameters:
-- 1: Items List
-- 2: File prefix
-- 3: Size (optional: default 50)
-- 4: File Suffix (optional)
--
-- any characters in the list ':,. are stripped
--
-- if the item name has "(non digit characters)" at the end,
-- it is replaced with "-non digit characters"
------
local p = {}
function p.getItems(frame)
local tArgs
if frame == mw.getCurrentFrame() then
fParent = frame:getParent()
tArgs = fParent.args
if (fParent.args[1]) then
tArgs = fParent.args
else
tArgs = frame.args
end
else
tArgs = frame
end
local items = tArgs[1] or ""
local prefix = tArgs[2] or ""
local size = tArgs[3]
local suffix = tArgs[4] or ""
if not size or size == "" then
size = "50"
end
items = mw.ustring.gsub(items, "^%s*(.-)%s*$", "%1") or ''
-- check for !! (! at the end of item)
-- replace with ^!
-- ^ will be replaced back to ! before returning
items = mw.ustring.gsub(items, "!!", "^!")
local itemsFile = ""
local space = ""
for it in mw.text.gsplit(items, "%s*!%s*") do
local lcIt = mw.ustring.gsub(it, "^([^%(]+)%s%(([^%d]+)%)$", "%1-%2")
if not lcIt then lcIt = it end
lcIt = mw.ustring.gsub(mw.ustring.lower(lcIt), "[':%,%.]", "")
itemsFile = itemsFile .. space
.. "[[File:"
.. prefix
.. "-"
.. lcIt
.. ".png|x"
.. size
.. "px|link="
.. it
if suffix and suffix ~= "" then
itemsFile = itemsFile .. " " .. suffix
end
itemsFile = itemsFile .. "]]"
space = " "
end
-- replace back any ! (delimiter) changed earlier
itemsFile = mw.ustring.gsub(itemsFile, "%^", "!")
return itemsFile
end
return p
-- </nowiki>
-- [[Category:Lua Modules]]