Module:ItemEffect

From He is Coming Official Wiki
Revision as of 11:03, 14 November 2025 by Benjiminio (talk | contribs) (Created page with "local p = {} function p.main(frame) local item = frame.args[1] or "" if item == "" then return "No item specified" end -- Normalize item name (replace spaces with underscores) local safeItem = item:gsub(" ", "_") -- Build effect page title local effectPage = mw.title.new("He_is_Coming/" .. safeItem .. "/effect") if not effectPage or not effectPage.exists then return "Effect page not found" end -- Get the raw wik...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.main(frame)
    local item = frame.args[1] or ""
    if item == "" then
        return "No item specified"
    end

    -- Normalize item name (replace spaces with underscores)
    local safeItem = item:gsub(" ", "_")

    -- Build effect page title
    local effectPage = mw.title.new("He_is_Coming/" .. safeItem .. "/effect")
    if not effectPage or not effectPage.exists then
        return "Effect page not found"
    end

    -- Get the raw wikitext of the effect page
    local effectText = effectPage:getContent() or ""

    -- Get ColorText module
    local ColorText = mw.getContentModule("ColorText")
    if not ColorText or not ColorText.colors then
        return effectText  -- fallback: no coloring if ColorText missing
    end

    -- Replace all keywords dynamically
    for keyword, _ in pairs(ColorText.colors) do
        local colored = ColorText.main{args={keyword}}
        -- Replace whole words only, case-insensitive
        effectText = effectText:gsub("(%f[%w])"..keyword.."(%f[%W])", colored)
    end

    return effectText
end

return p