Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Transclude: Difference between revisions

From Teriock
Content deleted Content added
Created page with "local p = {} -- Helper function to trim whitespace from a string local function trim(s) return s:match('^%s*(.-)%s*$') end -- Main function to transclude pages function p.transclude(frame) local input = frame.args[1] or '' local output = {} -- Split input into lines for line in input:gmatch('[^\r\n]+') do -- Trim whitespace and add transclusion syntax local page = trim(line) if page ~= '' then table.insert(ou..."
 
No edit summary
Line 11: Line 11:
local output = {}
local output = {}
-- Handle both newline-separated and space-separated inputs
-- Split input into lines
local pages = {}
-- First split by newlines
for line in input:gmatch('[^\r\n]+') do
for line in input:gmatch('[^\r\n]+') do
-- Trim whitespace and add transclusion syntax
-- Then split each line by spaces
local page = trim(line)
for page in line:gmatch('%S+') do
table.insert(pages, page)
end
end
-- Process each page
for _, page in ipairs(pages) do
page = trim(page)
if page ~= '' then
if page ~= '' then
table.insert(output, string.format('{{%s}}', page))
table.insert(output, string.format('{{%s}}', page))

Revision as of 11:44, 14 January 2025

Documentation for this module may be created at Module:Transclude/doc

local p = {}

-- Helper function to trim whitespace from a string
local function trim(s)
    return s:match('^%s*(.-)%s*$')
end

-- Main function to transclude pages
function p.transclude(frame)
    local input = frame.args[1] or ''
    local output = {}
    
    -- Handle both newline-separated and space-separated inputs
    local pages = {}
    -- First split by newlines
    for line in input:gmatch('[^\r\n]+') do
        -- Then split each line by spaces
        for page in line:gmatch('%S+') do
            table.insert(pages, page)
        end
    end
    
    -- Process each page
    for _, page in ipairs(pages) do
        page = trim(page)
        if page ~= '' then
            table.insert(output, string.format('{{%s}}', page))
        end
    end
    
    -- Join all transclusions with newlines
    return table.concat(output, '\n')
end

-- Function to handle direct template calls
function p.transcludeFromTemplate(frame)
    local parent = frame:getParent()
    return p.transclude(parent)
end

return p