Module:ConceptRelations2

From No Subject
Jump to navigation Jump to search

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame)
    local root = mw.html.create('div')

    for i=1,50 do
        local target=args["relation_"..i.."_target"]
        if not target then break end

        local raw=args["relation_"..i.."_type"] or "Related to"
        local direction=args["relation_"..i.."_direction"]
        local content=args["relation_"..i.."_content"] or ""

        local icons={
          ["Introduced by"]="📘",
          ["Derived from"]="🌱",
          ["Reformulated by"]="🔁",
          ["Expanded by"]="➕",
          ["Contrasts with"]="⚡",
          ["Related to"]="🔗"
        }

        local icon=icons[raw] or "🔗"

        local block=root:tag("div"):addClass("concept-relation-block")
        local head=block:tag("div"):addClass("concept-relation-header")

        head:tag("span"):addClass("concept-relation-icon"):attr("title",raw):wikitext(icon)
        head:tag("span"):wikitext(raw.." [["..target.."]]")

        if content~="" then
            block:tag("div"):wikitext(content)
        end

        if direction=="bidirectional" then
            root:wikitext("[[Category:Concept referenced by "..mw.title.getCurrentTitle().text.."]]")
        end
    end

    return tostring(root)
end

return p