Module:ConceptRelations4
Jump to navigation
Jump to search
Documentation for this module may be created at Module:ConceptRelations4/doc
-- Module:ConceptRelations
-- Handles contributor blocks and conceptual relationship blocks for Template:Infobox_concept
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
-- Smart Link Creation
local function makeLink(target)
if not target or target == "" then return "" end
-- If the string already contains wikilinks (e.g. "[[A]], [[B]]"), return as is
if target:find("%[%[") then
return target
end
-- Otherwise, build the link
return "[[" .. target .. "]]"
end
-- ========================================
-- CONTRIBUTOR BLOCKS
-- ========================================
function p.contributors(frame)
local args = frame:getParent().args
local output = {}
-- Process up to 20 contributors
-- Removed 'break' to allow for gaps in numbering
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>')
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
-- Removed 'break' to allow for gaps in numbering
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>')
end
end
return table.concat(output, "\n")
end
return p