Module:ItemEffect: Difference between revisions

From He is Coming Official Wiki
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..."
 
Benjiminio (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Require the ColorText module using full path
local color = require("Module:He_is_Coming/ColorText")
-- Fetch the 'effect' parameter from the item's infobox template
function p.main(frame)
function p.main(frame)
     local item = frame.args[1] or ""
     local itemName = frame.args[1] or ""
     if item == "" then
     if itemName == "" then
         return "No item specified"
         return "Error: no item specified"
     end
     end


     -- Normalize item name (replace spaces with underscores)
     -- Attempt to get the content of the item's template
     local safeItem = item:gsub(" ", "_")
     local templateName = "Template:" .. itemName
 
     local templateFrame = mw.getContentFrame(templateName)
    -- Build effect page title
     if not templateFrame then
     local effectPage = mw.title.new("He_is_Coming/" .. safeItem .. "/effect")
         return "Error: item page or template not found"
     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
     end


     -- Replace all keywords dynamically
     -- Get the 'effect' parameter
     for keyword, _ in pairs(ColorText.colors) do
     local effectText = templateFrame:getParameter("effect") or ""
        local colored = ColorText.main{args={keyword}}
    if effectText == "" then
        -- Replace whole words only, case-insensitive
        return "Effect not found on item page"
        effectText = effectText:gsub("(%f[%w])"..keyword.."(%f[%W])", colored)
     end
     end


     return effectText
    -- Pass effect text to ColorText module for keyword highlighting
    -- ColorText expects a table with args[1] containing the text
     return color.main({ args = { effectText } })
end
end


return p
return p

Latest revision as of 11:41, 14 November 2025

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

local p = {}

-- Require the ColorText module using full path
local color = require("Module:He_is_Coming/ColorText")

-- Fetch the 'effect' parameter from the item's infobox template
function p.main(frame)
    local itemName = frame.args[1] or ""
    if itemName == "" then
        return "Error: no item specified"
    end

    -- Attempt to get the content of the item's template
    local templateName = "Template:" .. itemName
    local templateFrame = mw.getContentFrame(templateName)
    if not templateFrame then
        return "Error: item page or template not found"
    end

    -- Get the 'effect' parameter
    local effectText = templateFrame:getParameter("effect") or ""
    if effectText == "" then
        return "Effect not found on item page"
    end

    -- Pass effect text to ColorText module for keyword highlighting
    -- ColorText expects a table with args[1] containing the text
    return color.main({ args = { effectText } })
end

return p