Module:ListUtils: Difference between revisions

No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 87: Line 87:
                     table.insert(out, '[[' .. catNs .. ':' .. plain .. ']]')
                     table.insert(out, '[[' .. catNs .. ':' .. plain .. ']]')
                 end
                 end
                 -- Property link (optional if property is non-empty)
                 -- Property annotation (hidden label so nothing shows)
                 if property and property ~= '' then
                 if property and property ~= '' then
                     table.insert(out, '[[' .. property .. '::' .. plain .. ']]')
                     table.insert(out, '[[' .. property .. '::' .. plain .. '| ]]')
                 end
                 end
                seen[plain] = true
            end
        end
    end
    return table.concat(out, ' ')
end
-- Internal: props only
local function propsFromList(list, property)
    list = trim(list or '')
    if list == '' or not property or property == '' then
        return ''
    end
    local parts = mw.text.split(list, ',')
    local out = {}
    local seen = {}
    for _, part in ipairs(parts) do
        local s = trim(part)
        if s ~= '' then
            local plain = stripLinks(s)
            plain = mw.ustring.match(plain, '([^|]+)') or plain
            plain = trim(plain)
            if plain ~= '' and not seen[plain] then
                table.insert(out, '[[' .. property .. '::' .. plain .. '| ]]')
                 seen[plain] = true
                 seen[plain] = true
             end
             end
Line 115: Line 143:
end
end


-- Backwards-compatible wrapper specifically for verticals
-- Public: props-only entry point
function p.verticalCatsAndProps(frame)
-- {{#invoke:ListUtils|propsOnly|A, B, C|HasThing}}
     local list = frame.args[1] or frame.args.list or ''
-- {{#invoke:ListUtils|propsOnly|list=A, B, C|property=HasThing}}
     return catsAndPropsFromList(list, 'HasVertical', 'Category')
function p.propsOnly(frame)
     local list = frame.args.list or frame.args[1] or ''
    local property = frame.args.property or frame.args[2] or ''
     return propsFromList(list, property)
end
end


return p
return p