Module:ConceptRelations6

From No Subject
Jump to navigation Jump to search

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

-- Module:ConceptRelations
-- Handles contributor blocks and conceptual relationship blocks for Template:Infobox_concept
-- Parallel to Module:ThinkerRelations3 but adapted for concepts

local p = {}

-- ========================================
-- UTILITY FUNCTIONS
-- ========================================

-- Clean and normalize relationship type strings
local function normalizeType(typeStr)
    if not typeStr then return "" end
    return typeStr:lower():gsub("%s+", "-"):gsub("[/,]", "-")
end

-- Create wikilink from target name
local function makeLink(target)
    if not target or target == "" then return "" end
    -- Remove any existing wikilink brackets
    local cleaned = target:gsub("%[%[", ""):gsub("%]%]", "")
    return "[[" .. cleaned .. "]]"
end

-- ========================================
-- CONTRIBUTOR BLOCKS
-- ========================================

function p.contributors(frame)
    local args = frame:getParent().args
    local output = {}
    
    -- Process up to 20 contributors
    for i = 1, 20 do
        local name = args["contributor_" .. i .. "_name"]
        local year = args["contributor_" .. i .. "_year"]
        local ctype = args["contributor_" .. i .. "_type"]
        local content = args["contributor_" .. i .. "_content"]
        
        if name and name ~= "" then
            local normalizedType = normalizeType(ctype or "")
            
            -- Build the contributor block
            table.insert(output, '<div class="contributor-block ' .. normalizedType .. '">')
            
            -- Name with type tag
            table.insert(output, '  <div class="contributor-name">')
            table.insert(output, '    ' .. makeLink(name))
            if ctype and ctype ~= "" then
                table.insert(output, '    <span class="contributor-type-tag">' .. ctype .. '</span>')
            end
            table.insert(output, '  </div>')
            
            -- Year (if provided)
            if year and year ~= "" then
                table.insert(output, '  <div class="contributor-year">' .. year .. '</div>')
            end
            
            -- Content/description
            if content and content ~= "" then
                table.insert(output, '  <div class="contributor-content">' .. content .. '</div>')
            end
            
            table.insert(output, '</div>')
        else
            -- Stop at first empty contributor slot
            break
        end
    end
    
    return table.concat(output, "\n")
end

-- ========================================
-- CONCEPTUAL RELATIONSHIPS
-- ========================================

function p.relations(frame)
    local args = frame:getParent().args
    local output = {}
    
    -- Process up to 50 relationships
    for i = 1, 50 do
        local target = args["relation_" .. i .. "_target"]
        local rtype = args["relation_" .. i .. "_type"]
        local content = args["relation_" .. i .. "_content"]
        
        if target and target ~= "" then
            local normalizedType = normalizeType(rtype or "")
            
            -- Build the relation block
            table.insert(output, '<div class="relation-block ' .. normalizedType .. '">')
            
            -- Target with type tag
            table.insert(output, '  <div class="relation-target">')
            table.insert(output, '    ' .. makeLink(target))
            if rtype and rtype ~= "" then
                table.insert(output, '    <span class="relation-type-tag">' .. rtype .. '</span>')
            end
            table.insert(output, '  </div>')
            
            -- Content/description
            if content and content ~= "" then
                table.insert(output, '  <div class="relation-content">' .. content .. '</div>')
            end
            
            table.insert(output, '</div>')
        else
            -- Stop at first empty relation slot
            break
        end
    end
    
    return table.concat(output, "\n")
end

-- ========================================
-- DEBUGGING FUNCTION (OPTIONAL)
-- ========================================

function p.debug(frame)
    local args = frame:getParent().args
    local output = {"<pre>"}
    
    table.insert(output, "=== CONTRIBUTORS ===")
    for i = 1, 10 do
        local name = args["contributor_" .. i .. "_name"]
        if name then
            table.insert(output, "Contributor " .. i .. ": " .. name)
        end
    end
    
    table.insert(output, "\n=== RELATIONS ===")
    for i = 1, 10 do
        local target = args["relation_" .. i .. "_target"]
        if target then
            table.insert(output, "Relation " .. i .. ": " .. target)
        end
    end
    
    table.insert(output, "</pre>")
    return table.concat(output, "\n")
end

return p