Module:Parser: Difference between revisions
From 20R1
Created page with "local p = {} -- Trim whitespace from a string local function trim(s) return s:match("^%s*(.-)%s*$") end -- Main entry point called from the template function p.parse(frame) local args = frame.args local prop = args.property or "" local list = args.list or "" -- Split by comma (allowing optional spaces around commas) local items = {} for item in list:gmatch("[^,]+") do local cleaned = trim(item) if cleaned ~= "" then..." |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 9: | Line 9: | ||
function p.parse(frame) | function p.parse(frame) | ||
local args = frame.args | local args = frame.args | ||
local hide = args.hide or "" | |||
local prop = args.property or "" | local prop = args.property or "" | ||
local list = args.list or "" | local list = args.list or "" | ||
| Line 23: | Line 24: | ||
-- Build SMW property assignments | -- Build SMW property assignments | ||
local output = {} | local output = {} | ||
for _, | for _, item in ipairs(items) do | ||
-- Use [[Property:Attendee::value]] syntax for SMW | -- Use [[Property:Attendee::value]] syntax for SMW | ||
table.insert(output, "[["..prop.."::" .. mw.text.encode( | if hide == '~' then | ||
show = '|' | |||
else | |||
show = '' | |||
end | |||
table.insert(output, "[["..prop.."::" .. mw.text.encode(item) .. show .."]]") | |||
end | end | ||
Latest revision as of 22:16, 17 November 2025
Documentation for this module may be created at Module:Parser/doc
local p = {}
-- Trim whitespace from a string
local function trim(s)
return s:match("^%s*(.-)%s*$")
end
-- Main entry point called from the template
function p.parse(frame)
local args = frame.args
local hide = args.hide or ""
local prop = args.property or ""
local list = args.list or ""
-- Split by comma (allowing optional spaces around commas)
local items = {}
for item in list:gmatch("[^,]+") do
local cleaned = trim(item)
if cleaned ~= "" then
table.insert(items, cleaned)
end
end
-- Build SMW property assignments
local output = {}
for _, item in ipairs(items) do
-- Use [[Property:Attendee::value]] syntax for SMW
if hide == '~' then
show = '|'
else
show = ''
end
table.insert(output, "[["..prop.."::" .. mw.text.encode(item) .. show .."]]")
end
-- Join all assignments with newlines
return table.concat(output, "\n")
end
return p
