Template:ItemEffect: Difference between revisions

From He is Coming Official Wiki
Benjiminio (talk | contribs)
mNo edit summary
Benjiminio (talk | contribs)
mNo edit summary
Line 1: Line 1:
{{:{{#replace:{{{1}}}| |_}}/effect}}
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

Revision as of 10:59, 14 November 2025

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